Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to get the value of nsAccVal:IBANNumber in the below soap UI XML. But getting the exception of Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

My entire Soap envelope is as below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <nsAccVal:EAIServices xmlns:nsAccVal="http://www.iibcdm.T24systems.com/FTAccountValidation" xmlns:nsT24sys="http://www.iibcdm.T24systems.com" xmlns:nsHdr="http://www.iibcdm.header.com">
         <nsAccVal:Header>
            <nsHdr:MsgVersion>v 1.0</nsHdr:MsgVersion>
            <nsHdr:SrcAppId>IPI</nsHdr:SrcAppId>
            <nsHdr:SrcMsgId>20180916191655591</nsHdr:SrcMsgId>
            <nsHdr:SrcAppTimestamp>2018-09-09T19:12:55.5884814+04:00</nsHdr:SrcAppTimestamp>
            <nsHdr:SrvCode>QACCVAL</nsHdr:SrvCode>
            <nsHdr:SrvName>FTAccountValidation</nsHdr:SrvName>
            <nsHdr:TrackingId>20180916191655590</nsHdr:TrackingId>
            <nsHdr:Language>en_US</nsHdr:Language>
            <nsHdr:BankId>FH</nsHdr:BankId>
            <nsHdr:InstanceId/>
            <nsHdr:TargetApp/>
            <nsHdr:Status>S</nsHdr:Status>
            <nsHdr:EAITimestamp>2018-09-09T19:12:55.5884814+04:00</nsHdr:EAITimestamp>
            <nsHdr:SecurityInfo>
               <nsHdr:UserId/>
               <nsHdr:Password/>
            </nsHdr:SecurityInfo>
            <nsHdr:AdditionalData>
               <nsHdr:Group/>
               <nsHdr:nameValue/>
            </nsHdr:AdditionalData>
         </nsAccVal:Header>
         <nsAccVal:Body>
            <nsAccVal:FTAccountValidationRes>
               <nsAccVal:IBANNumber>AE710810000001219412001</nsAccVal:IBANNumber>
               <nsAccVal:AccountStatus>Inactive</nsAccVal:AccountStatus>
               <nsAccVal:AvailableBalance>0.00</nsAccVal:AvailableBalance>
               <nsAccVal:AccountName>ACTITLE1</nsAccVal:AccountName>
               <nsAccVal:EmailId>B.BHATT@LIVE.COM</nsAccVal:EmailId>
               <nsAccVal:MobileNumber>0501671809</nsAccVal:MobileNumber>
            </nsAccVal:FTAccountValidationRes>
            <nsAccVal:ExceptionDetails>
               <nsHdr:ErrorCode>000</nsHdr:ErrorCode>
               <nsHdr:ErrorDescription>Success</nsHdr:ErrorDescription>
            </nsAccVal:ExceptionDetails>
         </nsAccVal:Body>
      </nsAccVal:EAIServices>
   </soapenv:Body>
</soapenv:Envelope>


What I have tried:

Code as below:
string ResponseAPI = System.IO.File.ReadAllText(@"F:\Sample.txt");


           XmlDocument xml = new XmlDocument();
           xml.LoadXml(ResponseAPI);
           //XmlNodeList xNodeList = xml.SelectNodes("/nsAccVal:EAIServices/nsAccVal:Body/nsAccVal:FTAccountValidationRes/nsAccVal:FTAccountValidationRes");
           XmlNodeList xNodeList = xml.SelectNodes("/nsAccVal:EAIServices/nsAccVal:Body/nsAccVal:FTAccountValidationRes");
Posted
Updated 18-Sep-18 9:02am
Comments
F-ES Sitecore 17-Sep-18 11:22am    
Google for using xmldocument with namesapces, you need to use XmlNamespaceManager to define your namespace and add the namespace prefix to your queries too. There is an example here

https://techoctave.com/c7/posts/113-c-reading-xml-with-namespace

but if you google you'll find more

1 solution

XML namespaces are a pain. The System.Xml.Linq namespace makes life slightly easier:
C#
XDocument xml = XDocument.Parse(ResponseAPI);
XNamespace nsAccVal = "http://www.iibcdm.T24systems.com/FTAccountValidation";
IEnumerable<XElement> xNodeList = xml.Descendants(nsAccVal + "IBANNumber");
string ibanNumber = (string)xNodeList.FirstOrDefault();

System.Xml.Linq Namespace | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900