Question

My XML looks like this:

<root>
<sets>
    <childSets>
        <childs>
            <child>
                <childId>11</childId>
        </child>
        <child>
            <childId>22</childId>
        </child>
        <child>
            <childId>33</childId>
        </child>
        <child>
            <childId>44</childId>
        </child>
[...]
    </childs>
</childSets>

    <childSets>
[...]
    </childSets>
</sets>
</root>

I want to pars all childId elements of child.

Actually, the result of my parsing is just the first childId of every childs element:

[...]
do {
  if ([[TBXML elementName:element] isEqualToString:@"childSet"]) {
  [...]
        TBXMLElement *xmlChildId        = [TBXML childElementNamed:@"childId"           parentElement:child];
  [...]
  }
} while ((element = element->nextSibling));  
[...]

In this case, I just get 11. Whats wrong here?

EDIT 1:

The solution is to find the first child of the child element and to parse the next elements of this, here it is:

This code is in the do while loop of the method traverseElement

do { [...]
        if ([[TBXML elementName:element] isEqualToString:@"childSet"]) {
        //find the first child
            if ((ChildPARENTELEMENT->firstChild)) {

            while (ChildOfCHILDELEMENT!=nil) {
                NSLog(@"....");

                 ChildOfCHILDELEMENT = [TBXML nextSiblingNamed:@"childs" searchFromElement:ChildOfCHILDELEMENT];

            }
        }
    }
while((element = element->nextSibling));

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top