A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Return individual word in an XML node

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    13

    Return individual word in an XML node

    I have a pretty simple question, how do I reference an individual word in an XML node. For example

    Code:
    <tag>word1 , word2 , word 3 , word 4, word5</tag>
    where I want to refer to all these tags individually instead of as a whole string.

    (I'm guessing I would use split() method to return an Array)

    If I can make the example return an Array of tags. How do I feed each each tag into it's own XML node? Like below,

    Code:
    <tag>word1</tag>
    <tag>word2</tag>
    <tag>word3</tag> 
    <tag>word4</tag>
    <tag>word5</tag>

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Once you have the XML node you are interested in, use toString() to get the content as a String. Then use split(",") to get an array of the parts (including spaces). You could then trim spaces out if you want. Then iterate through your new array and create new XML for each entry and use appendChild on some other XML to put your new tags in as child nodes.

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    13
    Thanks that was very helpful! Works perfectly now

    Code:
    for each(var bXML:XML in aXML)
    
    {
    
    var str:String = aXML;								
    var re:RegExp = /(,)/								
    var results:Array = str.split(re);
    								
    for each(var cXML:String in results)
    
    {															
    var indXML = new XML("<a>" + cXML + "</a>");
    if(indXML != ","){
    myXML.appendChild(indXML);
    
    }
    									
    indXML.@href = "http://www.ucubd.com";
    indXML.@style = "font-size: 8pt;";																		
    }
    }

Tags for this Thread

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