SelectSingleNode always returns null?

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

Taking this simplifed example of my XML:




        
1条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 22:01

    You're missing the XML namespace defined by the 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)
提交回复
热议问题