我正在尝试使用函数 GetElementById 获取 xml 的元素,但该函数始终返回 null。
//get xml text from a web service
string xml = aS.createTree();
XmlDocument tree = new XmlDocument();
tree.LoadXml(xml);
//get all nodes with the tag name "item"
XmlNodeList node = tree.GetElementsByTagName("item");
//just for test to see if i could get the attribute value which returns the expected
string idTemp = node[0].Attributes["ID"].Value;
XmlElement elem = tree.GetElementById("1");
elem 总是返回 null。你们能帮帮我吗?
顺便说一句,这是我试图解析的 xml:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE tree [
<!ELEMENT tree ANY>
<!ELEMENT item ANY>
<!ATTLIST item id ID #REQUIRED>
]>
<tree>
<item id="1">
<item id="2"></item>
</item>
<item id="5">
<item id="6"></item>
<item id="7">
<item id="8">
<item id="10">
<item id="11"></item>
</item>
</item>
<item id="9"></item>
</item>
</item>
</tree>