i am trying to use xpath-query in my app for xml parsing. my work is almost completed upto name space concept came into picture.i am always writing query correctly but its returning me the 0 objects in my array.i tried many blogs and also many posts in our stackoverflow.com but none of them not working..i hope my problem need small modification can any one modify my code.my code Thanks All. I think many people try to show my question is duplicate but it is different bec none of the questions not worked for my problem.please provide me your suggestion.your answer more help full for my work.
Asked
Active
Viewed 412 times
1 Answers
0
I take it you're using libxml along with Matt Gallagher's Cocoa wrappers for it? (It's helpful to put which third party libraries you're using in your question.)
When I did this, I modified Matt's code so that PerformXPathQuery
took an additional argument, an NSDictionary of namespaces. (The other functions such as PerformXMLXPathQuery
also took this argument, and pass through the object.)
Then, in PerformXPathQuery
, after creating the context, I registered the namespaces thus:
if (namespaces != nil)
{
for (NSString *key in namespaces)
{
xmlXPathRegisterNs(xpathCtx, (const xmlChar *)[key UTF8String], (const xmlChar *)[[namespaces objectForKey:key] UTF8String]);
}
}

Amy Worrall
- 16,250
- 3
- 42
- 65
-
Amorya Thanks for your answer.can you please provide some more info on namespace.. – ajay May 23 '11 at 16:30
-
i am using libxml2 framework as well as xpathquery.m implementation class . – ajay May 23 '11 at 16:33
-
LarsH's answer to your other question has information about it. As he said, you'll need to modify your Xpath query to use a prefix for each tag. Then you have to register that prefix to the namespace URL that's in your XML: you can use my code for that. To take his example, with my code you would pass in an NSDictionary with one item, key `imsq`, value `http://www.imsglobal.org/xsd/imsqti_v2p1`. – Amy Worrall May 24 '11 at 08:06
-
@Amorya could you look at here tnx http://stackoverflow.com/questions/7007767/iphone-sdk-xml-mystery-after-adding-child-nodeforxpath-returns-nothing – Spring Aug 10 '11 at 15:12