touchXML XPath error, probably namespace issue
I am trying to parse xml document using touchXML on iOS. This is how xml
looks:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns1:session xmlns:ns1="http://xml.kamsoft.pl/ws/common"
id="01234567890123456789012345678901" />
<ns1:authToken xmlns:ns1="http://xml.kamsoft.pl/ws/common"
id="0123456789012345678901" />
</soapenv:Header>
<soapenv:Body>
<ns1:loginReturn
xmlns:ns1="http://xml.kamsoft.pl/ws/kaas/login_types">
[000]User has been logged successfully.
</ns1:loginReturn>
</soapenv:Body>
</soapenv:Envelope>
I need to parse id argument from both ns1:session and ns1:authToken.
There's some code:
CXMLDocument *doc = [[CXMLDocument alloc] initWithData:data options:0
error:nil];
NSArray *nodes = [doc
nodesForXPath:@"/soapenv:Envelope/soapenv:Header/ns1:session" error:nil];
Where data is just downloaded xml (there's no problem with data, I have
logged it to console and this is the same xml I have pasted above).
With this code, I am getting XPath error : Undefined namespace prefix. I
have tried other queries, like /soapenv:Envelope/soapenv:Header or just
/soapenv:Envelope, but I am getting the same error.
I have tried http://www.xpathtester.com/test with these XPaths.
/soapenv:Envelope/soapenv:Header and /soapenv:Envelope are working, I am
getting node list, but /soapenv:Envelope/soapenv:Header/ns1:session
produces exception XPath expression uses unbound namespace prefix ns1.
Can you please help me with this? I don't need proper, good looking xml
parsing, just these two attributes or information, that there's no such
node in xml document.
No comments:
Post a Comment