1
最後に、よく言われていない質問を削除し、最も簡単な形にしました。私はルートノードを選択しようとしていますが、それはnullとして戻ってきます。XmlElementからルートノードを選択できません
は、ここに私のコードですここ
XmlDocument input = new XmlDocument();
XmlDocument output = new XmlDocument();
input.Load(@"simple.xml");
XmlNode outputNode = output.CreateNode(XmlNodeType.Element, input.ChildNodes[1].Name, null);
Console.WriteLine(outputNode.SelectSingleNode("root") == null ? "null" : "node found");
Console.WriteLine(outputNode.SelectSingleNode("/root") == null ? "null" : "node found");
Console.WriteLine(outputNode.SelectSingleNode("//root") == null ? "null" : "node found");
//After doing this, /root and //root return the root node
output.AppendChild(node);
Console.WriteLine(outputNode.SelectSingleNode("root") == null ? "null" : "node found");
Console.WriteLine(outputNode.SelectSingleNode("/root") == null ? "null" : "node found");
Console.WriteLine(outputNode.SelectSingleNode("//root") == null ? "null" : "node found");
EDIT私のXML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<children>
<child>Clark</child>
<child>Bruce</child>
<child>Peter</child>
</children>
</root>
だと:@Marcは、右のトラックに私を置きます。実際にノードをXmlDocumentに追加すると、そのノードは正常に動作しました。
する
は、実際には理由.ChildNodesのあなたの子供のノードであるかもしれない[1] ...多分一見の価値。 – Craig