Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HARDWARRIOR

macrumors member
Original poster
Nov 17, 2008
52
0
Hi!
I have a simple XML

Code:
<?xml version="1.0" encoding="utf-8"?><errorCode>2</errorCode><error>Invalid username</error>

and I want to parse it in my app.
First I tried touchXML, but it returned error

Code:
Entity: line 1: parser error : Extra content at the end of the document
<?xml version="1.0" encoding="utf-8"?><errorCode>2</errorCode><error>Invalid use
                                                              ^

Dont know what it means. Googling for that error did not helped.
So I tried NSXMLParser and got error too

Code:
Parsing error: Operation could not be completed. (NSXMLParserErrorDomain error 5.)
parsing ended

error number 5 means

Code:
NSXMLParserPrematureDocumentEndError
The document ended unexpectedly.

accordinc to docs.
But I really dont understand where is error in such a simple XML! Also W3C online validar told me that XML is valid

Code:
docElt: {None}errorCode
No declaration for document root found, validation was lax
The schema(s) used for schema-validation had no errors
No schema-validity problems were found in the target

So where is error in that XML?
 

Pring

macrumors 6502
Sep 17, 2003
310
0
Your XML is invalid. Everything needs to be under a root element. Something like

<?xml version="1.0" encoding="utf-8"?>
<errorDetails>
<errorCode>2</errorCode>
<error>Invalid username</error>​
</errorDetails>
 

chbeer

macrumors member
Sep 22, 2008
82
0
Berlin
Hi!
I have a simple XML

Code:
<?xml version="1.0" encoding="utf-8"?><errorCode>2</errorCode><error>Invalid username</error>

[...]

So where is error in that XML?

It's no XML. You don't have a single root element. It helps a lot to reformat it:

Code:
<?xml version="1.0" encoding="utf-8"?>
<errorCode>
  2
</errorCode>
<error>
  Invalid username
</error>

You see, there is not one root-element but two: errorCode and error.

One correct version would be:
Code:
<?xml version="1.0" encoding="utf-8"?>
<error>
  <errorCode>
    2
  </errorCode>
  <errorText>
    Invalid username
  </errorText>
</error>

HTH
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.