1

I have a xml document which has only one element in the document. This is the whole document.

<?xml version="1.0" encoding="UTF-8"?>
<error>key ! is invalid</error>

But when i try to parse it, it says this document has no element at all. In other words when i try to access the rootElement it says "null"

Here is the code i am using.

   CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];

   NSLog(@"Root: %@",[[rssParser rootElement] name]);

But its working OK when i have the following document.

<?xml version="1.0" encoding="UTF-8"?>
<response>
<list><category>(noun)</category><synonyms>angstrom|angstrom unit|A|metric linear unit</synonyms></list>
<list><category>(noun)</category><synonyms>vitamin A|antiophthalmic factor|axerophthol|A|fat-soluble vitamin</synonyms></list>
<list><category>(noun)</category><synonyms>deoxyadenosine monophosphate|A|nucleotide</synonyms></list>
<list><category>(noun)</category><synonyms>adenine|A|purine</synonyms></list>
<list><category>(noun)</category><synonyms>ampere|amp|A|current unit</synonyms></list>

<list><category>(noun)</category><synonyms>A|letter a|letter|letter of the alphabet|alphabetic character</synonyms></list>
<list><category>(noun)</category><synonyms>A|type A|group A|blood group|blood type</synonyms></list>
</response>

Please tell me what is wroing with this.

Thanks

4

1 回答 1

1

如果您愿意尝试不同的解析器,我建议您使用 TBXML ...它有据可查,并且可能是最快和最好的解析器。

于 2010-09-08T08:44:30.810 回答