SelectSingleNode always returns null?

后端 未结 1 643
温柔的废话
温柔的废话 2021-02-19 21:30

Taking this simplifed example of my XML:




        
相关标签:
1条回答
  • 2021-02-19 22:01

    You're missing the XML namespace defined by the <message> node in your SelectSingleNode call. Assuming oss is an XmlDocument instance, you need to do this:

    XmlNamespaceManager nsMgr = new XmlNamespaceManager(oss.NameTable);
    nsMgr.AddNamespace("ns", "http://www.mydomain.com/MyDataFeed");
    
    XmlNode errorNode = oss.SelectSingleNode("/ns:message/ns:error", nsMgr);
    

    Marc

    0 讨论(0)
提交回复
热议问题