This content has been marked as final. Show 5 replies
has lots of info about using dataProvider.
getItemByAttribute is not supported
I read through the example, and didn't see how it relates.
I have been playing with things, and what I found was that the dataprovider is an object, not XML, even though I specify "e4x" on my resultFormat tag of the HTTPService that gets the data.
I think I need to figure out how to get the data back from an HTTPService request in the proper format before I can do what I need to do. All suggestions are welcome.
I think I can get the data in XML format using;
MenuData = XML(menuLoad.lastResult);
Once in this format I have been unable to find a way to loop (recursively, I presume) through the children to find the child I need.
I have looked through documentation, forums, blogs etc. and no one (that I could find) has an example of how to loop through an XML tree. Here is an example that does not work;
private function traceNodes(theNode:XML):void
for(var child in theNode.)
I really need help on this one.
you have two seperate issues that are tangled together , lets first seperate them
1st issue) you need to get correct XML. to do so Alert, or trace yourXMLObject.toXMLString().
as soon as you have your desired XML object traversing it is trivial .
here is one example :
traversing XMLNode of following nature :
<application manager="my.application.manager.insance" >
<module name="nmyModuleABC" default="yes" type="IApplication" access="ACCESS_ROLE_123" >
<help id="someID" url="myhelp.xml" />
<module name="anotherModule.swf" type="IModule" access="ACCESS_1234" >
<help id="anotherId" url="anotherelp.xml" />
for each (var aModule:XML in this._configurationXML.application.module)
e4x is very powerfull and fairly simple. if you know XPath is even easier.
Okay, using help from the posts, I finally wrote a routine that will walk an XML tree. Here is what I wrote;
private function getXMLByAttribute(xmlInputNode:XML,strNodeName:String,strAttribute:String,strAttributeVal ue:String):XML
var xmlReturnNode:XML = null;
for each (var xmlCurrentNode:XML in xmlInputNode[strNodeName])
if (xmlCurrentNode.@[strAttribute] == strAttributeValue) return xmlCurrentNode;
xmlReturnNode = getXMLByAttribute(xmlCurrentNode,strNodeName,strAttribute,strAttributeValue);
if (xmlReturnNode != null) break;
It will in fact return a node from an xml tree. You can call it like;
myNode:XML = getXMLByAttribute(myXMLData,"*","myAttribute","myValue");
the above will return an XML data set containing the first node where the attribute myAttribute is equal to myValue. The * says search all nodes, you can replace it with a string equal to a nodename, like myXMLData.myNodeName.
But, this doesn't give me what I need (I think). What I need really need is to be able to add a new node as a child below this one, or to delete this node. So what I really need (I think) is a pointer into the original XML dataset suitable to be used in an insert/delete XML method.