XML Document SelectSingleNode returns null

前端 未结 5 967
你的背包
你的背包 2020-12-08 14:34

I am trying to read XML from stream reader and am also getting response XML. But when i try to read its nodes it is always returning null.

var request = (Htt         


        
5条回答
  •  醉话见心
    2020-12-08 15:13

    The XML document uses the default namespace "http://ratequote.usfnet.usfc.com/v2/x1". You need to change the SelectSingleNode call to use this namespace.

    You need to setup a namspace manager and then supply it to SelectSingleNode.

    var nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("rate", "http://ratequote.usfnet.usfc.com/v2/x1");
    var node = xmlDocument.SelectSingleNode("//rate:RateQuote", nsmgr);
    

    EDIT The RateQuoteResponse element has a default namespace xmlns="...". This means that all elements use this namespace also, unless specifically overridden.

提交回复
热议问题