A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How do I create dynamic XML from multiple simple strings?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    12

    How do I create dynamic XML from multiple simple strings?

    Okay here's my problem.

    Say I have a class that just contains Strings that contain XML:



    package
    {
    public class XmlStrs
    {
    public static const MSG_ID:String = '<msg_id> "msg_id" </msg_id>';

    public static const TICKET:String = '<ticket> "ticket" </ticket>';
    public static const TOKEN:String = '<token> "token" </token>';

    //And so on.
    }
    }//end package.

    Now I want to use this class within another class to create various
    complex XML strings. So something like this:

    package
    {
    public class formatter
    {
    private var inputStrs:XmlStrs = new XmlStrs();
    public function createTicketToken( pParam1:int, pParam2:string):XML
    {
    var jXml:XML;
    with (inputStrs)
    {
    jXml = XML(TICKET (pParam1)) + XML(TOKEN(pParam2));
    }
    return jXml
    }//end function
    }// end class
    }// end package.

    Obviously my assignment statement is broken. I can't pass pParam1 into the static string. I've seen where you can piece something together using:

    'various xml "data" various xml"

    but I need to create more complex data than that. Is there a way to pass a variable into a string and then pass that into the XML constructor?

    Help.

    Ulti.

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    Theres a whole bunch of information here on how to do this.

    http://www.actionscript.org/forums/s....php3?p=789609

    I would at the very least explicitly set a root node in your xml declaration. And then you use the appendChild call to add nodes. There's a whole host of api calls available :


    http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/XML.html

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