I am trying to parse an XML file using NSXMLParser, but the method [parser columnNumber] returns a wrong value. For example, in my .xml I have:
...
<Test><something type="great"><lol>Joy</lol> // Three elements in the same line
...
</something>
</Test>
For the element “Test”, I get the correct line:
<Test><something type="great"><lol>Joy</lol>
But the column number is “6”.
In the same line, I get the column number “22” for the element “something”:
"great"><lol>Joy</lol>
Is this an expected behavior?
Edit. Two headaches ago I was still hopeful. Now I think it is much better to reformat the file to avoid strange things like elements in the same line and do some whitespace cleaning. But this is strange. What a bug.
Well, this is quite strange, but I’m writing an answer anyway.
I was doing some tests with an example XML and some line/column numbers got from NSXML.
Some logs in the form of
(I’m pretty noob at intelligent debugging)
There is a formula that always works1, that is:
For example, consider the second line and the log near (A):
I expect that
columnPositionequals0, in fact:Note that NSXML’s
columnNumberis still15whatever I write inside the “class” tag, but it’s9when I remove the entire tag. With the following line:I expect that
columnPositionequals0, in fact:Now, consider the following line and the log near (B):
I’m expecting that
columnNumberequals3. In fact:Well, this is strange. I think this is not an excellent solution, but at least it works. I can’t simply remove the whitespace in the beginning of the string, because it fails if there is a line like:
What do you think about this? I’m feeling kinda noob but I’m going to check this one as the accepted answer if there is no other way. I’m looking forward to what you guys think.
1 Avoided formal proof for brevity and lack of will.