Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:24:48+00:00 2026-05-25T18:24:48+00:00

I am trying to parse an XML file using NSXMLParser, but the method [parser

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:24:49+00:00Added an answer on May 25, 2026 at 6:24 pm

    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.

    <?xml version="1.0"?>
    <catalog class="something">
       <book id="bk101">
          <author>Gambardella, Matthew</author>
          <title>XML Developer's Guide</title>
          <genre>Computer</genre>
          <price>44.95</price>
          <publish_date>2000-10-01</publish_date>
          <description>An in-depth look at creating applications 
          with XML.</description>
    ...
    

    Some logs in the form of

    column, line
    OPEN/CLOS element
    

    (I’m pretty noob at intelligent debugging)

    15, 2 (A)
    OPEN catalog
    12, 3 (B)
    OPEN book
    14, 4
    OPEN author
    CLOS author
    13, 5
    OPEN title
    CLOS title
    13, 6
    OPEN genre
    CLOS genre
    13, 7
    OPEN price
    CLOS price
    20, 8
    OPEN publish_date
    CLOS publish_date
    19, 9
    OPEN description
    CLOS description
    CLOS book
    ...
    

    There is a formula that always works1, that is:

    columnPosition = columnNumber - length("<element>")
    

    For example, consider the second line and the log near (A):

    <catalog class="something">
    

    I expect that columnPosition equals 0, in fact:

    len("<catalog class>") = 15
    0 = 15 - length("<catalog class>")
    

    Note that NSXML’s columnNumber is still 15 whatever I write inside the “class” tag, but it’s 9 when I remove the entire tag. With the following line:

    <catalog>
    

    I expect that columnPosition equals 0, in fact:

    length("<catalog>") = 9
    0 = 9 - length("<catalog>")
    

    Now, consider the following line and the log near (B):

       <book id="bk101">
    

    I’m expecting that columnNumber equals 3. In fact:

    length("<book id>") = 9
    3 = 12 - length("<book id>")
    

    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:

    <catalog class="something"><book id="bk101">
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse an xml file using XmlReader but although I am
I'm trying to parse an XML file using PHP, but I get an error
I am trying to parse a xml file that i have (using javascript DOM).
I'm trying to parse a XML file using TBXML . However, this parser has
I am Trying To Use NSXMLParser to parse an xml file using cocoa which
I'm trying to parse an xml file using lxml. xml.etree allowed me to simply
I am trying to parse an XML file using the SAX interface of libxml2
I am trying to parse XML in Perl using XML::SAX parser . My query
I'm using jQuery to parse an XML file, and I'm trying to push each
I'm using NSXMLParser to parse a small XML file containing information about videos. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.