locked
Namespace prefix 'ns0' is not defined RRS feed

  • Question

  • User1216489373 posted

    Hi Experts,

    I am getting error "Namespace prefix 'ns0' is not defined".

    My XML is

    <?xml version="1.0"?>
    <ns0:AuthResponseSchema xmlns:ns0="http://services.test.com/Auths/">
      <ns0:AuthResponseResult submittertraceid="b715337b-4b75-41ef-b617-e33d728f913c" transactionid="1020374" type="HI-IREQ">
        <ns0:PayerResponseXML type="ReviewResponse">
          <ns0:UtilizationMgmtOrg>
            <ns0:Name type="PR">
              <ns0:LastOrgName>TEST</ns0:LastOrgName>
              <ns0:Identifier type="PI">XXX</ns0:Identifier>
            </ns0:Name>
          </ns0:UtilizationMgmtOrg>
        </ns0:PayerResponseXML>
      </ns0:AuthResponseResult>
    </ns0:AuthResponseSchema>

    My Code is:

                    XmlDocument results = new XmlDocument();
                    results.Load(@"C:\WebApp\WebApp\auth.xml");
    
                    var nsmgr = new XmlNamespaceManager(results.NameTable);
                    nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
    
                    XmlNodeList xnList = results.SelectNodes("ns0:AuthResponseSchema", nsmgr);

    My code is breaking at 

    XmlNodeList xnList = results.SelectNodes("ns0:AuthResponseSchema", nsmgr);

    Please Help.

    Thanks,
    Rahul

    Friday, April 29, 2016 7:55 AM

Answers

  • User-271186128 posted

    Hi Rahul,

    I am getting error "Namespace prefix 'ns0' is not defined".

    As for this issue, please modify your code as below:

                    XmlDocument results = new XmlDocument();
                    results.Load(@"C:\WebApp\WebApp\auth.xml");
    
                    var nsmgr = new XmlNamespaceManager(results.NameTable);
                    nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
                    nsmgr.AddNamespace("ns0", "http://services.test.com/Auths/");
    XmlNodeList xnList = results.SelectNodes("ns0:AuthResponseSchema", nsmgr);

    More details, you can refer to this article:

    https://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.addnamespace(v=vs.110).aspx

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 29, 2016 11:03 AM