Parse XML with succint syntax

旧时模样 提交于 2019-12-02 03:05:44

The fundamental difference here is that his XML doesn't have default namespace, while yours has default namespace declared here :

xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1"

By the way, this topic (XPath query against XML with default namespace) has been asked a lot previously in various forms here in SO. Notice that the element where a default namespace is declared and all of its descendants without a prefix and without a different default namespace declaration are considered to be in that aforementioned default namespace. And one possible way to query an element in a namespace is by mapping a prefix to the namespace uri using a namespace manager, and then using the mapped prefix properly in the XPath, for example :

var nsManager As New XmlNamespaceManager(new NameTable());
nsManager.AddNamespace("d", "http://schemas.microsoft.com/search/local/ws/rest/v1");
XmlNode xmlNode = xmlDoc.SelectSingleNode("//d:StatusDescription", nsManager);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!