petersego
asked on
how do I edit xml in as3
Can someone provide me with a simple example of editing a xml-node and attribute through a input-field in as3.
ASKER
No, Ive been occupied with other works lately.
What I would like to see is an example of how to change the content of one node and one attribute somewhere down a complex xml-structure.
In the simple xml below lets say I want to change the attribute width to 250 and the item-node Clothes to Ships.
In reality I want to allow the user to change every node and attribute - but through a form-based interface before sending the xml back to a php-script.
What I would like to see is an example of how to change the content of one node and one attribute somewhere down a complex xml-structure.
In the simple xml below lets say I want to change the attribute width to 250 and the item-node Clothes to Ships.
In reality I want to allow the user to change every node and attribute - but through a form-based interface before sending the xml back to a php-script.
<settings color='0x000000' size='9' font='arial' width='200' height='300'>
<items>
<item>Books</item>
<item>Clothes</item>
<item>CDs</item>
<item>Cars</item>
</items>
</settings>
oh are you using php?
and where is the original xml coming from, the harddrive / server etc?
and where is the original xml coming from, the harddrive / server etc?
ASKER
its loaded from a server - the same place as the php-script.
var myXML:XML = new XML();
var XML_URL:String = "strangestore.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myxmlLoader:URLLoader = new URLLoader(myXMLURL);
myxmlLoader.addEventListen er("comple te", xmlLoaded);
function xmlLoaded(event:Event):voi d
{
myXML = XML(myxmlLoader.data);
var myXML:XML = new XML();
var XML_URL:String = "strangestore.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myxmlLoader:URLLoader = new URLLoader(myXMLURL);
myxmlLoader.addEventListen
function xmlLoaded(event:Event):voi
{
myXML = XML(myxmlLoader.data);
i remember fiddling with it the last time you asked and i'm sure it did work.
have a look at this link to get you started for the syntax
http://blog.everythingflex.com/2008/10/01/filereferencesave-in-flash-player-10/
basically load the xml as you have, stick it in a textfield. allow the user to edit data in that textfield, and then you call fileReference.save() i think.
have a look at this link to get you started for the syntax
http://blog.everythingflex.com/2008/10/01/filereferencesave-in-flash-player-10/
basically load the xml as you have, stick it in a textfield. allow the user to edit data in that textfield, and then you call fileReference.save() i think.
ASKER
Yes, but thats what I want to avoid.
I want the user to edit the xml through a form-based interface.
Like I lined up above...
I want the user to edit the xml through a form-based interface.
Like I lined up above...
i'm not following - is my understanding of form based interface different to yours?
you have the xml sitting on the server( a physical .xml file)
you load it into flash.
display the xml inside the form which you're going to create with a save button
no?
also I'm thinking if you're using php you don't need the FileReference you can pass the textfield data back to the php and have that update the xml file with the user's changes.
you have the xml sitting on the server( a physical .xml file)
you load it into flash.
display the xml inside the form which you're going to create with a save button
no?
also I'm thinking if you're using php you don't need the FileReference you can pass the textfield data back to the php and have that update the xml file with the user's changes.
ASKER
When I say form-based I mean that each node and attribute should have its own input-field.
ah okay i don't think there's a quick way to do it. you'll have to write the code.
you need to loop through your xml and get all the nodes and in each node check if there's attributes etc and create a textfield accordingly, and populate the textfield with that data.
then when they submit it take all the textfields.text and concatenate into one long string. parse the string as XML and then send that through to your PHP to make the file.
do you know how to work with xml in AS3? if not here's a very good resource.
http://dispatchevent.org/roger/as3-e4x-rundown/
i don't think it will be too difficult but it will be a lot of work.
are you building this because you need an xml editor (i know they were available for purchase in AS2 - maybe it would be worth your while to purchase one?)
you need to loop through your xml and get all the nodes and in each node check if there's attributes etc and create a textfield accordingly, and populate the textfield with that data.
then when they submit it take all the textfields.text and concatenate into one long string. parse the string as XML and then send that through to your PHP to make the file.
do you know how to work with xml in AS3? if not here's a very good resource.
http://dispatchevent.org/roger/as3-e4x-rundown/
i don't think it will be too difficult but it will be a lot of work.
are you building this because you need an xml editor (i know they were available for purchase in AS2 - maybe it would be worth your while to purchase one?)
ASKER
Yes, I know how to import and showing the content of xml in as3.
Im not interested in building an entire xml-editor, but just making it possible to update the content of some xml-node or xml-attributes in an input-field where Ive placed that content - as I lined up earlier.
I kinda understand that you dont know how to do this, so if you dont mind I will close the question and start a new one, where I more clearly outline the problem from the start. :)
Im not interested in building an entire xml-editor, but just making it possible to update the content of some xml-node or xml-attributes in an input-field where Ive placed that content - as I lined up earlier.
I kinda understand that you dont know how to do this, so if you dont mind I will close the question and start a new one, where I more clearly outline the problem from the start. :)
yeah sure, i also want to understand the problem clearly.
things you might want to explain so anybody trying to assist can understand.
1. is the xml node you want to edit going to be dynamic or is there only one specific node you want the user to be able to edit?
2. if the latter how do you want them to choose which node?
3. if the former then don't understand the problem.
4. have you got the php part working?
things you might want to explain so anybody trying to assist can understand.
1. is the xml node you want to edit going to be dynamic or is there only one specific node you want the user to be able to edit?
2. if the latter how do you want them to choose which node?
3. if the former then don't understand the problem.
4. have you got the php part working?
ASKER
Thanks, good advises. Regarding the last point, Im not absolutely sure.
I found an example of saving an internally created xml-node but I havent tried with an imported complete xml-file. (see snippet)
I found an example of saving an internally created xml-node but I havent tried with an imported complete xml-file. (see snippet)
<?php
$filename = "readwrite/simple_edit.xml";
$raw_xml = file_get_contents("php://input");
print $raw_xml;
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
?>
this dude should be able to help you along.
near the bottom. his code does work but i'm not sure if it works in line with what you're trying to achieve in terms of "where Ive placed that content - as I lined up earlier."
good luck with it, you can close or delete this now.
near the bottom. his code does work but i'm not sure if it works in line with what you're trying to achieve in terms of "where Ive placed that content - as I lined up earlier."
good luck with it, you can close or delete this now.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
describe exact scenario of what you're doing, i'll try again to create an example.