A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: stupid XML value to text field question

  1. #1
    Member
    Join Date
    Jun 2001
    Posts
    33

    stupid XML value to text field question

    Hi there -

    I'm totally new to xml and am trying to get the most basic functions to work correctly! I'm sorry if this is a dupe, but I didn't see anything here dumbed down enough to my level! :-)

    So, I'm pretty close, but no cigar. All I want to do is pull an XML value into a dynamic text field and something has gone awry!

    I am able to get the xml to load. I am also able to pull the xml tags and value into the dynamic text field, but I cannot figure out how to pull only the value.

    Here is the line of code that should pull the xml value into the text field:

    Code:
    phoneBook.text = contactXML.childNodes[1].childNodes[0].childNodes[0];
    I thought that this would return a last name (such as Jones). However, I get: <last>Jones</last>

    If I do this:

    Code:
    phoneBook.text = contactXML.childNodes[1].childNodes[0].childNodes[0].nodeValue;
    it returns Null

    One thing I noticed is that when I run a nodeType, it returns a 1. textNodes are 3's, but I'm not sure this is the issue. I think my XML is okay... Here's an excerpt taken from the larger doc:

    Code:
    <?xml version = "1.0" encoding = "UTF-8"?>
       <phoneBook>
    	<contact id="1">
    	   <nameFirst>John</nameFirst>
                    <nameLast>Doe</nameLast>
    	   <address> 123 JohnDOE Lane</address>
    	   <phone>123 456</phone>
    	</contact>
       </phoneBook>
    What am I missing here?

    Thanks for your help!

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    any text between tags is ALSO a child. In other words John is a childNode[0] of the tag <nameFirst>.

    Hence the following should work:

    Code:
    phoneBook.text = contactXML.childNodes[1].childNodes[0].childNodes[0].childNodes[0];

    Also as a suggestion another name for childNode[0] is firstChild

    So the above could be made into

    Code:
    contactXML.childNodes[1].firstChild.firstChild.firstChild;
    hope this helps!!
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center