KissXML and namespaces

212 views
Skip to first unread message

Nathan de Vries

unread,
Aug 20, 2009, 2:58:33 AM8/20/09
to kis...@googlegroups.com
Hi folks,

I'm working on a project at the moment with a SOAP API, and after
playing with KissXML it looks to be the best tool for the job. The
only issue I've come across so far is to do with querying nodes via
xpath, when the node has a namespace that's not declared in the
rootElement of the DDXMLDocument. Without having used NSXMLDocument,
I'm unsure whether this is a bug or a feature. The following test
should be fairly self-explanatory:

> - (void) testDDXMLDocumentWithNamespaces {
> NSString* xml = @""
> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
> "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/
> \">"
> "<soapenv:Body>"
> "<ns1:SomeMethodResponse xmlns:ns1=\"http://example.com/
> schema\">"
> "<ns1:Items>"
> "<ns1:Item>Foo</ns1:Item>"
> "<ns1:Item>Bar</ns1:Item>"
> "<ns1:Item>Baz</ns1:Item>"
> "</ns1:Items>"
> "</ns1:SomeMethodResponse>"
> "</soapenv:Body>"
> "</soapenv:Envelope>";
>

> DDXMLDocument* document = [[DDXMLDocument alloc]
> initWithXMLString:xml options:0 error:nil];

> NSArray* items = [document nodesForXPath:@"//ns1:Item" error:nil];
>
> GHAssertTrue([items count] == 3, nil); // FAILS
>
> // Add the namespace to the root of the document
> [[document rootElement] addNamespace:[DDXMLNode
> namespaceWithName:@"ns1" stringValue:@"http://example.com/schema"]];
>

> GHAssertTrue([items count] == 3, nil); // SUCCEEDS

> }


Even if I call nodesForXPath: on the "<ns1:SomeMethodResponse>"
element, I still get 0 items back from the query. Is this expected, or
am I missing something important?


Cheers,

Nathan de Vries

Reply all
Reply to author
Forward
0 new messages