xpath-nested expression
<root>
<node nodeid="12" depnode="4"/>
<node nodeid="1" frm="12,45"/>
<node nodeid="45" depnode="3"/>
<node nodeid="24" depnode="2"/>
<node nodeid="2" frm="24,36"/>
<node nodeid="36" depnode="1"/>
</root>
in the above xml code, some "node" elemenet nodes, have "frm"-attribute.
How do i write a single xpath expression, so that by passing a nodeid="1", i get "frm" attribute. Then the "frm" attribute can be parsed and searched for the nodeid="which frm tag consists" then get the attributes of those nodes.....
example---
exp1="//node[@nodeid="1"]/@frm"
exp2="//node[@nodeid="this value should be passed from the exp1"]/@depnode"
this exactly gets the attributes with 2 different expressions.
Is there any way, where we can put it in one expression.
below given is the java code(the way i have parsed using xPATH)
//sample code which is working fine with 2 xpath expressions.....
private void test() throws Exception
{
Node frm_values=null;
Node dep_Node=null;
inputSource= new InputSource(new FileInputStream(new File(this.fileName)));
NodeList frm_nodes=(NodeList) xPath.evaluate("//node[@nodeid="+1+"]/@frm", inputSource, XPathConstants.NODESET);
System.out.println("length of the .."+frm_nodes.getLength());
for(int i=0; i<frm_nodes.getLength(); i++)
{
frm_values=frm_nodes.item(i);
System.out.println("frm tag values.... "+frm_values.getNodeValue());
String frm_string=frm_values.getNodeValue();
String[] frm_array=frm_string.split(",");
for(int k=0; k<frm_array.length; k++)
{
System.out.println("values...."+frm_array[k]);
inputSource= new InputSource(new FileInputStream(new File(this.fileName)));
NodeList dep_list=(NodeList) xPath.evaluate("//node[@nodeid="+frm_array[k]+"]/@depnode", inputSource, XPathConstants.NODESET);
for(int ctr=0; ctr< dep_list.getLength(); ctr++)
{
dep_Node=dep_list.item(ctr);
System.out.println("dependent nodes node's "+dep_Node.getNodeValue());
}
}
}
|