-
constructing xml nodes
I need to create this kind of xml with the flash XML object, and I just can't figure it out how.
PHP Code:
<canvas updatated="16.10.2002">
<object type=textField>
<x>100</x>
<y>150</y>
<w>400</w>
<h>150</h>
<text>Blablabla</text>
<fontSize>15</fontSize>
</object>
<object type=imageField>
<x>700</x>
<y>850</y>
<w>400</w>
<h>150</h>
<url>keys.jpg</url>
</object>
</canvas>
I've browsed the web and all I managed to do is this:
Code:
mapXML = new XML();
XCanvas = mapXML.createElement("canvas");
XCanvas.attributes.updatated="16.10.2002";
mapXML.appendChild(XCanvas);
It's easy to read xml, but it seems like creating a new object is a more difficult job. A sample would do the trick for me, just can't find any online.
-
Ok, it seems that it's impossible to do that with the xml object.
I have seen this is done with strings, like
PHP Code:
tempObj = '<object name="'+myObjData.names[i]+'" x="'+myObjData.x[i]+'" y="'+myObjData.y[i]+'">\n';
tempObj += ' <action>'+myObjData.action[i]+'</action>\n';
tempObj += ' <border>'+myObjData.border[i]+'</border>\n';
tempObj += ' <bgcolor>'+myObjData.bgcolor[i]+'</bgcolor>\n';
tempObj += '</object>\n';
thanks to Ron Polka for giving me this ideea with one of his movies.
Last edited by AKADaJack; 10-21-2002 at 05:44 PM.
-
You're on the right path with your first attempt, using the XML object. For every element you want in the final XML, you need to use createElement and appendChild, plus set whatever attributes you may have. For text nodes inside of an element, you'll use createTextNode.
Code:
mapXML = new XML();
var canvasnode, objectnode, xnode, textnode;
canvasnode = mapXML.createElement("canvas");
canvasnode.attributes.updatated="16.10.2002";
mapXML.appendChild(canvasnode);
objectnode = mapXML.createElement("object");
objectnode.attributes.type = "textfield";
canvasnode.appendChild(objectnode);
xnode = mapXML.createElement("x");
objectnode.appendChild(xnode);
textnode = mapXML.createTextNode("100");
xnode.appendChild(textnode);
trace(mapXML);
-
Ok, that's great, and it's not difficult at all. Easyer than with strings. thanks a lot.
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
|