|
-
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
-
Bearded (M|G)od
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?
-
Senior Member
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>
<infoOne> variableOne </infoOne>
<infoTwo> variableTwo </infoTwo>
<infoThree> variableThree </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..
-
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?
-
Senior Member
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.
-
Thanks for the reply but it doesnt work, it just echoes, ("<infoOne>"+variableOne+"</infoOne>");
-
Senior Member
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|