GetElementById()找不到标签? [英] GetElementById() not finding the tag?
本文介绍了GetElementById()找不到标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有效的XML文件,正在由以下.NET C#Windows服务读取. 有问题的标签(u1_000)绝对位于元素中:
I have a valid XML file being read by the following .NET C# windows service. The tag in question (u1_000) is absolutely in the element:
<book id="u1_000" category="xyz">
是否由于某种原因,GetElementById()找不到带有标签的Book元素? -谢谢
Is there some reason the GetElementById() does not find the Book element with the tag? - thanks
XmlDocument doc = new XmlDocument();
doc.Load("C:\\j.xml");
XmlElement ee = doc.GetElementById("U1_000");
<book id="U1_000" category="web">
推荐答案
如果没有其他问题,也许可以使用xpath作为备份:
If nothing else, perhaps use xpath as a backup:
string id = "u1_000";
string query = string.Format("//*[@id='{0}']", id); // or "//book[@id='{0}']"
XmlElement el = (XmlElement)doc.SelectSingleNode(query);
这篇关于GetElementById()找不到标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文