0

I have an xml I am using TouchXML to parse it. Basically, a Lookup looks like this:

                    <Lookup>
                    <LookupID>201150103538705</LookupID>
                    <LookupName  />
                    <LookupType>Category</LookupType>
                    <VendorID>10</VendorID>
                    </Lookup>

When I do this, it returns all Lookup in the document:

NSArray *lookups = [[xmlDoc rootElement] nodesForXPath:@"//TestA:Lookup"
                                    namespaceMappings:mappings 
                                                error:nil];

What I want to do is get all lookups whos LookupType is equal to Composition (string compare). So this is what's I have tried and it returns null:

NSArray *lookups = [[xmlDoc rootElement] nodesForXPath:@"//TestA:Lookup[LookupType=\"Composition\"]" 
                                    namespaceMappings:mappings 
                                                error:nil];

Thanks

sumderungHAY
  • 1,337
  • 18
  • 30

1 Answers1

0

Does the XPath //TestA:Lookup[TestA:LookupType='Composition'] do what you want? If the parent element is in a namespace then its child too so I think you need a prefix on both elements in your path.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Hey that worked! thanks. One last question: if i want to get LookupName rather than Lookup, how would I do it? Currently I tried this but it doesn't work: @"//TestA:Lookup[TestA:LookupType='Composition']/LookupName" – sumderungHAY Jun 21 '11 at 11:18
  • Well if the elements are in a namespace then in your XPath expression you need to use a prefix to qualify element names so try `"//TestA:Lookup[TestA:LookupType='Composition']/TestA:LookupName`. – Martin Honnen Jun 21 '11 at 11:50