How do you get an XML object reference instead of the value in as3
I feel like this question has a really easy answer and I'm just overlooking it. I need to get a pointer to a piece of XML. I can get a pointer to the parent node and everything works but trying to get a pointer to a node that has no children just returns the 开发者_JAVA百科value of that node.
Here's an example:
<body>
<parentNode>
<subNode>value</subNode>
</parentNode>
</body>
So to get a pointer to "parentNode", I would say something like this:
var parentNode = xml.parentNode;
If you trace that it would be the xml shown above without the body tags.
Below I will try to get a pointer to the subNode:
var subNode = xml.parentNode.subNode;
Tracing subNode would be just the value and there is no pointer to the original xml object, so editing the subNode var would only change its value, not the one in the original XML object.
How do I get a pointer to the subNode so it can be edited to change the original xml object?
Here is a code example :
var xml : XML = <a><b><c>test</c></b></a>;
var cNode : XML = XML(xml.b.c);
trace("1:", cNode.toXMLString());
cNode.setChildren("Hello King Kong");
trace("2:", cNode.toXMLString());
trace("3:", xml);
//output :
//1: <c>test</c>
//2: <c>Hello King Kong</c>
//3: <a>
// <b>
// <c>Hello King Kong</c>
// </b>
//</a>
Actually, if you trace the node, it will be casted to a string, getting the childnode textvalue, and not the actual node. If you put the node in a variable of type XML, it will be the actual node.
So
node:XML = c; will be the node.
node:String = c; will be the textvalue of that node.
精彩评论