Note that there are some explanatory texts on larger screens.

plurals
  1. POobjective C - How to parse recursive node from xml using libxml2
    primarykey
    data
    text
    <p>Below is the XML with recursive elements:</p> <pre><code>&lt;Tree&gt; &lt;Node name="books" label="books"&gt; &lt;Node name="Maths" label="Maths"&gt; &lt;Node name="Topic 1" label="Topic 1"&gt; &lt;Node name="chapter 1" label="chapter 1"/&gt; &lt;Node name="chapter 2" label="chapter 2"/&gt; &lt;Node name="chapter 3" label="chapter 3"/&gt; &lt;Node name="chapter 4" label="chapter 4"/&gt; &lt;Node name="chapter 5" label="chapter 5"/&gt; &lt;/Node&gt; &lt;/Node&gt; &lt;Node name="Physics" label="Physics"&gt; &lt;Node name="Topic 1" label="Topic 1"&gt; &lt;Node name="chapter 1" label="chapter 1"/&gt; &lt;Node name="chapter 2" label="chapter 2"/&gt; &lt;Node name="chapter 3" label="chapter 3"/&gt; &lt;/Node&gt; &lt;/Node&gt; &lt;/Node&gt; &lt;Node name="Pens" label="Pens"&gt; &lt;/Node&gt; &lt;/Tree&gt; </code></pre> <p>H</p> <p>I tried using the following code for getting the recursive values, But I can get the first level attributes, But can't get the second level "Node" element attribute value,</p> <pre><code>-(void)parse { NSString *strVal = [[NSString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding]; xmlDoc * doc = xmlParseMemory(xmlData.bytes, xmlData.length); xmlNodePtr nodePtr =xmlDocGetRootElement(doc); nodePtr = nodePtr-&gt;xmlChildrenNode; getChild(nodePtr, (xmlChar *)"Node"); } int recursive = 0; void getChild(xmlNodePtr nodePtr, xmlChar *elementName) { NSLog(@"recursive: %d",recursive ++); xmlNodePtr tempPtr = nodePtr; while (tempPtr!= NULL) { if (!xmlStrcmp(tempPtr-&gt;name, elementName)) { xmlChar *v = xmlGetProp(tempPtr, (const xmlChar *)"name"); NSLog(@"element:%s field:%s val: %s",elementName, "name", v); // nodePtr = nodePtr-&gt;next; } tempPtr = tempPtr -&gt; next; } xmlNodePtr nodePtr2 = nodePtr -&gt; xmlChildrenNode; getChild(nodePtr2, elementName); } </code></pre> <p>and the result is:</p> <p>2011-12-09 01:12:12.271 LibXMLParser[4123:207] recursive: 0 2011-12-09 01:12:12.275 LibXMLParser[4123:207] element:SystemNode field:name val: MSG 2011-12-09 01:12:12.276 LibXMLParser[4123:207] element:SystemNode field:name val: SAP 2011-12-09 01:12:12.277 LibXMLParser[4123:207] recursive: 1</p> <p>Can anyone give me answer for how to get the recursively get child of a node from the root?</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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