I'm having a bit of problems with simple XML coding. I'm using a simple flash application to write a XML containing customer data (simple stuff, like phone number, name, email, etc).
I understand how to write XML manually, but my issue comes when I want to create a element inside another element. I'm using AS3.
So, for example, I have the following xml.
<xmlcontainer>
<client>
<name>Marco</name>
<phone>123456789</phone>
</client>
<client>
<name>Roberto</name>
<phone>987654321</phone>
</client>
</xmlcontainer>
If I want to add a new element, thats fine. But i'm not sure how to add a element INSIDE once its done in code.
I have been using .appendChild(<client/>) so far, but errors pop up as I do element inside element. I tried writing as a text element (i.e., manually) by just doing .appendChild("<client><name>Marco</name></client>"), but the less than and great than symbols don't pass along correctly.
Can someone help me out here?
EDIT: As requested, here is the full code.
function appendXML():void{
var xmlData:XML = new XML();
var xmlrequest:URLRequest = new URLRequest(String("xml/clientelist.xml"));
xmlLoader.load(xmlrequest);
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
function LoadXML(e:Event):void
{
xmlData = new XML(e.target.data);
xmlData.appendChild(<pessoa/>);
xmlData.appendChild(<id/>);
xmlData.id.appendChild(idfield.text);
xmlData.appendChild(<nome/>);
xmlData.nome.appendChild(nomefield.text);
xmlData.appendChild(<email/>);
xmlData.email.appendChild(emailfield.text);
xmlData.appendChild(<contacto/>);
xmlData.contacto.appendChild(contacto1field.text);
trace(xmlData);
var fileb:FileReference = new FileReference;
fileb.save( xmlData, "clientelist.xml" );
}
(pessoa = person, nome = name, contacto = phonenumber)