dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: how to extract nodeValue ?

  1. #1
    Junior Member
    Join Date
    Jul 2006
    Posts
    20

    how to extract nodeValue ?

    Hi !

    How can I access the data inside a tag ? I mean

    <year> 2006 </year>

    how can I extract the '2006' ? isn't it by

    xmlObj.firstChild.nodeValue ??

    I'm working with the MX 2004 (not the prof.) and it doesn't work

    Appreciate every advise

    cheers

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Code:
    xmlObj = new XML ();
    xmlObj.ignoreWhite = true;
    xmlObj.load ("year.xml");
    
    xmlObj.onLoad = function(){
    a = xmlObj.firstChild;
    b = a.childNodes;
    trace(b); // 2006
    }
    
    /* --year.xml--
    <year> 2006 </year>
    */

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    an example of using nodeValue
    Code:
    xmlObj = new XML ();
    xmlObj.ignoreWhite = true;
    xmlObj.load ("year.xml");
    
    xmlObj.onLoad = function(){
    a = xmlObj.firstChild.childNodes;
    len = a.length;
    trace("using firstChild:");
    for (var i = 0; i<len; i++)   
    trace("\t"+a[i].firstChild);
    
    trace(" ");
    
    trace("using firstChild.nodeValue:");
    for (var i = 0; i<len; i++)  
    trace("\t"+a[i].firstChild.nodeValue);
    
    };
    /* --output--
    using firstChild:
    	sugar
    	Tate &amp; Lyle  // maintains the &amp; entity
    	2006
     
    using firstChild.nodeValue:
    	sugar
    	Tate & Lyle  // converts to ampersand character (&).
    	2006
    */
    
    /* --year.xml--
    <login>
    <username>sugar</username>
    <password>Tate &amp; Lyle</password>
    <year>2006</year>
    </login>
    */

  4. #4
    Cheap Bear Imitation eRkLaErBaEr's Avatar
    Join Date
    Mar 2003
    Location
    Forests
    Posts
    308
    Simple put: You have to treat the text inside your year-element as a node as well (in fact, it is a node; a text node). So to access the 2006, you'd do the following:
    Code:
    xmlObj.firstChild.firstChild.nodeValue
    Pink signature?


  5. #5
    Junior Member
    Join Date
    Jul 2006
    Posts
    20
    Thanks a lot guys, it did the trick...

    General question :
    If anyone works in the industry (professional flash developer) -
    what is xml and flash mainly used for ?

  6. #6
    Member
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    64
    XML is a good way to display and change information inside the Flash file (.fla) without having to go into the Flash file itself. So if you want to change/update news on your Flash website, simply change the information inside the XML file (which should obviously be scripted to load inside the Flash file)
    That's one way I see it being useful.

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