SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    weird "#text" node in my XML object?????

    I have a XML object that I have from a HttpXMLRequest (Ajax). Wen I parse it, it surrounds the nodes with a "#text" node. but if i parse the XML into an object from a variable within my script, its perfect.

    can ne1 tell me y this does this. it only seems to add the weird "#text" nodes when im ajaxing.

    thanks for any responses.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I suspect that's because your server-side script (or whatever it is you're getting the XML from) has (or is adding in the case of a scrip) whitespace in between each node. It's sending it nicely-indented or at least on a line-by-line basis. For example:
    Code:
    <name>
      <firstname>David</firstname>
      <lastname>Williams</lastname>
    </name>
    instead of
    Code:
    <name><firstname>David</firstname><lastname>Williams</lastname></name>

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    I suspect that's because your server-side script (or whatever it is you're getting the XML from) has (or is adding in the case of a scrip) whitespace in between each node. It's sending it nicely-indented or at least on a line-by-line basis. For example:
    Code:
    <name>
      <firstname>David</firstname>
      <lastname>Williams</lastname>
    </name>
    instead of
    Code:
    <name><firstname>David</firstname><lastname>Williams</lastname></name>
    yeah my xml code is structured correctly. still gives me un-needed "#text" nodes. i can filter them out using an if statement, so it hasnt stop my progress. just the annoyance of havn an if statement wen its not needed.

    thanks for ur reply!!

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you use getElementsByTagName instead of childNodes (or nextSibling), you won't have this problem.

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i am looping through the nodes, so i have to use childNodes[i].firstChild.nodeValue

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If they all have the same nodeName, just do parent.getElementsByTagName('name') and loop through those. If they aren't, then maybe XPath is a better option.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •