Note that there are some explanatory texts on larger screens.

plurals
  1. PO(Kiss)XML xpath and default namespace
    primarykey
    data
    text
    <p>I am working on an iPhone project that needs to parse some xml. The xml may or may not include a default namespace. I need to know how to parse the xml in case it uses a default namespace. As I need to both read an write xml, I'm leaning towards using KissXML, but I'm open for suggestions.</p> <p>This is my code:</p> <pre><code>NSString *content = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bookstore" ofType:@"xml"] encoding:NSUTF8StringEncoding error:nil]; DDXMLDocument *theDocument = [[DDXMLDocument alloc] initWithXMLString:content options:0 error:nil]; NSArray *results = [theDocument nodesForXPath:@"//book" error:nil]; NSLog(@"%d", [results count]); </code></pre> <p>It works as expected on this xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;bookstore&gt; &lt;book category="COOKING"&gt; &lt;title lang="en"&gt;Everyday Italian&lt;/title&gt; &lt;/book&gt; &lt;book category="CHILDREN"&gt; &lt;title lang="en"&gt;Harry Potter&lt;/title&gt; &lt;/book&gt; &lt;/bookstore&gt; </code></pre> <p>But when the xml has a namespace, like this, it stops working:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;bookstore xmlns="[INSERT RANDOM NAMESPACE]"&gt; &lt;book category="COOKING"&gt; &lt;title lang="en"&gt;Everyday Italian&lt;/title&gt; &lt;/book&gt; &lt;book category="CHILDREN"&gt; &lt;title lang="en"&gt;Harry Potter&lt;/title&gt; &lt;/book&gt; &lt;/bookstore&gt; </code></pre> <p>Of course, I could just preprocess the string and remove the xmlns, though that feels like a sort of ugly hack. What is the proper way to handle this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload