0

I am new to GDataXMLNode and xml namespaces.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <ns1:StockDetails xmlns:ns1="urn:WinRetail:TestWebService">
         <ttStockDetail>
            <ttStockDetailRow>
               <iconname>Levels.png</iconname>
               <screenlabel>Inhand</screenlabel>
               <detail>Product Detail</detail>
            </ttStockDetailRow>
            <ttStockDetailRow>
               <iconname>Levels.png</iconname>
               <screenlabel>In transit</screenlabel>
               <detail>0</detail>
            </ttStockDetailRow>
         </ttStockDetail>
         <resultstring>OK</resultstring>
      </ns1:StockDetails >
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

How to parse this xml with namespaces using GDataXMLNode in Xcode? I don't want to use path. I want to get the element list in an array and then loop through it with a specific condition. I am unable to get the element list for 'StockDetails'.

Here is my code:

NSError *error;
GDataXMLDocument *xmlDocument = [[GDataXMLDocument alloc]initWithXMLString:fileContents options:0 error:&error];
NSDictionary *myNS = [NSDictionary dictionaryWithObjectsAndKeys: @"schemas.xmlsoap.org/soap/envelope/";, @"ns1", @"w3.org/2001/XMLSchema-instance";, @"ns2",,nil];
NSArray *tempArray = [xmlDocument.rootElement nodesForXPath:@"//ns1:Envelope" namespaces:myNS error:&error];
NSLog(@"%@",tempArray);

Please help.

Tom
  • 3,031
  • 1
  • 25
  • 33
  • Which programming language are you using? What have you tried to do so far? Can you post examples of your code that isn't working? – Tom Feb 10 '15 at 12:01
  • The code i tried is with xpath. I want to get all the elements under a specific element i.e use the function [xmlDocument.rootElement elementsForName:@""]; But how do i accommodate namespace here? Can you give me a way to get list of StockDetail without xpath? – user3102128 Feb 10 '15 at 12:52

0 Answers0