我试图将源系统中的XML转换为c#
中的相同xml这
# Merge all streams into stdout
$result = dotnet test *>&1
# Evaluate success/failure
if($LASTEXITCODE -eq 0)
{
# Success
}
else
{
# Failed, you can reconstruct stderr strings with:
$ErrorString = $result -join [System.Environment]::NewLine
}
要
<root>
<child><xml></xml></child>
</root>
我试着跟随到达
<root>
<child><![CDATA[<xml></xml>]]></child>
</root>
以下输出
var node = resXML.SelectSingleNode(@"/root/child");
node.ParentNode.ReplaceChild(node.AppendChild(resXML.CreateCDataSection(encodedXML)), node);
答案 0 :(得分:0)
试试这个
var sourceXml = "<root><child><xml></xml></child></root>";
var source = XDocument.Parse(sourceXml);
var result = new XDocument(new XElement("root",
source.Root
.Elements("child")
.Select(e => new XElement("child", new XCData(e.Value)))));
var resultXml = result.ToString();
答案 1 :(得分:0)
试试这个:
string xml = "<root><child><xml></xml></child></root>";
XmlDocument resXML = new XmlDocument();
resXML.LoadXml(xml);
var node = resXML.SelectSingleNode(@"/root/child");
node.AppendChild(resXML.CreateCDataSection(node.InnerText));
node.RemoveChild(node.FirstChild);
string output = resXML.OuterXml;