A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: XML help

  1. #1
    Member
    Join Date
    Aug 2007
    Posts
    33

    Exclamation XML help

    Hi, i have searched the web for days with no luck but i thought some of the flash gurus on this forum could help me =-)
    I have an xml file which contains this,
    Code:
    <partOne>
    </partOne>
    Its basicaly empty.
    However in flash it loads the xml into a variable, myXML.
    I then have three variables in flash that i want to put into the xml file so if i traced the myXML from flash it would look like this,
    Code:
    <partOne>
    <partTwo>
        <infoOne> variableOne </infoOne>
        <infoTwo> variableTwo </infoTwo>
        <infoThree> variableThree </infoThree>
    <partTwo>
    </partOne>
    and after i run the code again it looks like this,
    Code:
    <partOne>
    <partTwo>
        <infoOne> variableOne </infoOne>
        <infoTwo> variableTwo </infoTwo>
        <infoThree> variableThree </infoThree>
    <partTwo>
    <partTwo>
        <infoOne> variableOne </infoOne>
        <infoTwo> variableTwo </infoTwo>
        <infoThree> variableThree </infoThree>
    <partTwo>
    </partOne>
    Thanks for your time and i hope you can help me
    Chris

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    I think you're leaving out a key ingredient. What code is running to cause that? And what do you expect your result to be?

  3. #3
    Senior Member Awoogamuffin's Avatar
    Join Date
    Nov 2008
    Posts
    208
    Heya!

    Though I'm not entirely sure what it is you want to do, I think you'll want something like this:

    PHP Code:
    //your original XML
    var myXML:XML =
    <
    partOne>
    </
    partOne>

    //somewhere else, you make the extra item:
    var newItem:XML 
    <
    partTwo>
       <
    infoOnevariableOne </infoOne>
       <
    infoTwovariableTwo </infoTwo>
       <
    infoThreevariableThree </infoThree>
    </
    partTwo>

    myXML.appendChild(newItem); 
    This is using the E4X approach to playing with XML. I've been working a lot in XML lately, but in Flex. I imagine it works in Flash as well. I recommend you carefully read the documentation on how to use XML here:

    http://livedocs.adobe.com/flex/3/htm...th_XML_03.html

    You'll see that there are a lot of really powerful tools for reading and editing XMLs.

    I hope that's more or less what you were looking for..
    Check out my blog showing the development of my flash game, the Dregs of War

  4. #4
    Member
    Join Date
    Aug 2007
    Posts
    33
    Thanks Awoogamuffin its nearly working, the only problem that i have now is that the xml doenst read the variable, ie i have a varieble called variableOne and then this could equal 'hello' as a sting, when i put

    <infoOne> variableOne </infoOne>

    and then trace it, thats how it comes out, it doesnt say,

    <infoOne> hello </infoOne>

    do you now how to fix this?

  5. #5
    Senior Member Awoogamuffin's Avatar
    Join Date
    Nov 2008
    Posts
    208
    Heya, try treating it as a string, something like this:

    ("<infoOne>"+variableOne+"</infoOne>");

    Again, I'm too lazy to try this out, so forgive me if that doesn't work, but I'm pretty sure you can do that.
    Check out my blog showing the development of my flash game, the Dregs of War

  6. #6
    Member
    Join Date
    Aug 2007
    Posts
    33
    Thanks for the reply but it doesnt work, it just echoes, ("<infoOne>"+variableOne+"</infoOne>");

  7. #7
    Senior Member Awoogamuffin's Avatar
    Join Date
    Nov 2008
    Posts
    208
    Sorry, you need to use the XML() command to convert the string thing into an XML thing... I did this in flash and it worked:

    PHP Code:
    var bleh:int 9;

    var 
    myXML:XML XML("<stuff><item>"+bleh+"</item></stuff>");

    trace(myXML); 
    and the trace output was:

    PHP Code:
    <stuff>
      <
    item>9</item>
    </
    stuff
    As I said, i was too lazy to test all of this stuff earlier (the thing is, my local was doing 3€50 a cocktail for a limited time and I had to go). Now I think I've solved it, but I'm drunk, so I'm not so sure. If I'm right I want lots of hugs from everybody.
    Check out my blog showing the development of my flash game, the Dregs of War

  8. #8
    Member
    Join Date
    Aug 2007
    Posts
    33
    Was Perfect - And you were DRUNK =-) GENIOUS - HUGS all around!

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