Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > RSS and Atom
RSS and Atom Ask questions, get answers, discuss creating RSS and Atom feeds or programming apps or sites that create or consume RSS/Atom. Please leave any RSS/Atom politics out of this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the RSS and Atom section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 8th, 2008, 11:36 AM
Registered User
Join Date: Jul 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vinod.kumbar
Default xpath-nested expression

<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"/>

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.....

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++)
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++)
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++)
System.out.println("dependent nodes node's "+dep_Node.getNodeValue());


Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath 2.0 every expression stolte XSLT 5 November 24th, 2008 03:32 PM
XPath Expression NEO1976 XSLT 11 August 2nd, 2006 02:28 AM
nested xPath chetrity XML 5 June 8th, 2006 06:26 PM
Need help with XPATH Expression benomathew XML 1 May 9th, 2006 03:38 PM
Nested XPath Expression sonicDace XML 9 January 8th, 2004 12:17 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.