Does Flex provide any way to find out the depth of a given node in an XML.
For example, if XML is
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<node label="Session">
<node id="session_query1" label="DTM Buffer Size" />
<node id="session_query2" label="Buffer Block Size"/>
<node id="session_query3" label="Enable Test Load"/>
</node>
<node label="Workflow" >
<node id="workflow_query1" label="Enable HA Recovery"/>
<node id="workflow_query2" label="Suspend on Error"/>
</node>
<node label="Mapping" >
<node id="mapping_query1" label="SQL Override in SQ " />
<node id="mapping_query2" label="SQL Override in lookup" />
</node>
</root>
Assuming that root node is at depth 0, I should get the depth of the highlighted node as 2.
Thanks in Advance
Thanks Claudiu for replying.
I know this could be one solution. But, finding a depth of a node in XML, is a very trivial operation. I believe flex has some implementation for this. If this could be done in flex then it is waste to insert an extra column in XML.
Your XML has kind of the same structure so the depth of the child is always 2.
So if you click on a certain item in the tree you can access this information
e.g. id and label and also
the parent label. Tha should be enough to identify what operation to perform,
unless I am missing something.
C
Hi Mohd Fayaz,
what would be the depth of the node in this case..based on the higlighted item..??
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<node label="Session">
<node id="session_query1" label="DTM Buffer Size" />
<node id="session_query2" label="Buffer Block Size"/>
<node id="session_query3" label="Enable Test Load"/>
</node>
<node label="Workflow" >
<node id="workflow_query1" label="Enable HA Recovery"/>
<node id="workflow_query2" label="Suspend on Error"/>
</node>
<node label="Mapping" >
<node id="mapping_query1" label="SQL Override in SQ " />
<node id="mapping_query2" label="SQL Override in lookup" />
</node>
</root>
Also based on which attribute or value you want to identify the depth of the node..??
Is it based on the id attribute or the name attribute of the node..??
Thanks,
Bhasker
I am sorry Still I did not get exactly the depth concept you're talking about. Well make me clear with this..
Tell me depths of all the below highlighted items..??
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<node label="Session">
<node id="session_query1" label="DTM Buffer Size" />
<node id="session_query2" label="Buffer Block Size"/>
<node id="session_query3" label="Enable Test Load"/>
</node>
<node label="Workflow" >
<node id="workflow_query1" label="Enable HA Recovery"/>
<node id="workflow_query2" label="Suspend on Error"/>
</node>
<node label="Mapping">
<node id="mapping_query1" label="SQL Override in SQ " />
<node id="mapping_query2" label="SQL Override in lookup" />
<node id="mapping_query3" label="SQL Override" />
</node>
</root>
What do you mean exactly by "I want to find depth relative to the root node of XML"..?? Whether you are trying to find it relative to the root node of the highlighted xml above which is <node /> tag or else main root node which is the root for the whole xml <root />
Also you did not answer my question based on which attribute you want to know the depth of node..?? Is it based on name or id..??
Thanks,
Bhasker
Thanks,
Bhasker
Message was edited by: BhaskerChari
I don't think there is any way to do this in a simple manner in Flex.
I think all you can do is find the node in the data somehow, perhaps by walking down the XML, and keeping track of what level you are currently at.
The problem is, what if there are duplicate nodes? For example in the following case the bold nodes are duplicates, but one set are at level 2 and the other set are at level 3 (root node at level 1):
<root>
<node label="Session1">
<node id="session_query1" label="DTM Buffer Size" />
<node id="session_query2" label="Buffer Block Size"/>
<node id="session_query3" label="Enable Test Load"/>
</node>
<node label="Session2">
<node label="sub_Session2">
<node id="session_query1" label="DTM Buffer Size" />
<node id="session_query2" label="Buffer Block Size"/>
<node id="session_query3" label="Enable Test Load"/>
</node>
<node id="session_query1" label="DTM Buffer Size" />
<node id="session_query2" label="Buffer Block Size"/>
<node id="session_query3" label="Enable Test Load"/>
</node>
</root
Thanks All for you replies.
I know it can be done in multiple ways. But I wanted to know whehter Flex has some built in method in XML Class or some other, to know this directly.
Finding the depth at which a node is location in XML, is a very basic and essential feature.
I hope Flex development team will take care of this in future releases.
May be this could be of some help for some one still searching for the depth of the node in the tree.
private function handleTreeItemClickEvent(event:ListEvent):void {
trace(TreeListData(TreeItemRenderer(mytreeSource.itemToItemRenderer(e vent.currentTarget.selectedItem)).listData).depth);
}
North America
Europe, Middle East and Africa
Asia Pacific