XPath API getting Nodes

Hi,
My Data XML converted through Xstream
<Data>
<id>1</id>
<name>Name</name>
<DataList>
<DataVO>
<VoId>100</VoId>
<value>Value1</value>
<ProductList>
<Product>
<ProductId>P101</ProductId>
<PName>Product Name1</PName>
</Product>
<Product>
<ProductId>P102</ProductId>
<PName>Product Name2</PName>
</Product>
</ProductList>
</DataVO>
<DataVO>
<VoId>101</VoId>
<value>Value2</value>
<ProductList>
<Product>
<ProductId>P201</ProductId>
<PName>Product NameX1</PName>
</Product>
<Product>
<ProductId>P202</ProductId>
<PName>Product NameX2</PName>
</Product>
</ProductList>
</DataVO>
</DataList>
</Data>
The Problem
=========
While I am maintaining the relationship parsing through XPath API , I am giving to fetch products as API path as "/Data/Datalist/DataVO/ProductList/Product/ProductId" to get the list of products, I can able to get the 4 Products NodeList, But I want to set the each products "VoId" , Like P101 related with 100, P102 related with 100, P201 related with 101, P202 related with 101. Any Sugesstions, parsing logics?

Namespaces are not evaluated as XML constructs in XPath, but namespaces are required to be configured in the parser. Refer
Parsing with the JDOM XPath Class
http://www.onjava.com/pub/a/onjava/2005/01/12/xpath.html

Similar Messages

  • Getting the XPath from a Node

    Hey Folks, have a scenario where i need to link my data, i.e one node points to another node, e.g
    <data>
    <liability id="1">
    <value> 10000 </value>
    </liability>
    <asset id = "2">
    <value> 20000 </value>
    </asset>
    </data>
    so take the case above, i have a house which is an asset and i have a mortgage(liability) on that house, now i want to show that in my asset that there is a liability on this asset, so i need to come up with a way to link my asset to a liability, now easiest way in my thinking is just point to the XPath of the liability!! Now problem is this, at the data level that im working at, i know what data node im working on but i dont know its absolute path, in my case the above XML is just a snippet of what im dealing with, there is more hierarchical levels in my document!! Maybe im blind but i couldnt see from the API how to get the XPath of a node?? is there existing API which does this or will i have to go ahead and write something to come up with the XPath!! or does anyone have any other suggestions as to how i would do my link??
    The way i see my XML when finished is something like this
    <data>
    <liability id="1">
    <value> 10000 </value>
    </liability>
    <asset id = "2">
    <value> 20000 </value>
    <liability> /data/liability[@id='1'] </liability>
    </asset>
    </data>
    any thoughts are welcome,
    cheers,
    LL

    A better design would be to make your "id" attribute the key... looking back at your post, it seems that you have done that already. So your XML should just look something like this:<data>
    <liability id="1">
    <value> 10000 </value>
    </liability>
    <asset id = "2" liabilityid="1">
    <value> 20000 </value>
    </asset>
    </data>Then when your code needs to match the liability to the asset, you can easily build the XPath to find it. (Of course if there can be more than one liability per asset, you shouldn't use a liabilityid attribute as I did in the example.)
    PC&#178;

  • XPath API woes

    I'm trying to parse an XML document using the Actionscript 2
    XPath API. In one place I am using this as my xpath:
    presentation/content[@contentName='wellness']/section[@sectionName='Nutrition/Weight']'
    It fails when I use a slash in the "sectionName" attribute,
    when I remove the slash in the XML file and change the xpath
    accordingly it works fine. This XML is being generated for me, so I
    really have no choice in the matter, the slash has to stay. Is
    there something I can do to get around this problem?

    Mainly :
    - Speed,
    - Compact : 100Ko,
    - Pluggable kit for custom node usage,
    - JDK 1.1,
    - Featuring like lowercase/uppercase for HTML.
    Hope it replies,
    A.Brillant

  • How to get nodes and its attributes of an XML file usiong DOM parsing?

    how to get nodes and its attributes of an XML file usiong DOM parsing?
    i am new to XML parsing.......
    Thanking you........

    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;      ...
    //Setup the document
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
         Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
    //get elemets by name
         String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
    //This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data.

  • GET Node in logical database to be executed on a condition

    Dear Friends,
    I have used GET NODE (get pernr) to extract data from HR LDB- PNP.
    Using HR Report Category I have customized selection screen so that user cannot enter employee number (so that he can only see his payslip only) but can select just the period.
    So in the calling program I want "GET pernr" to execute only when pernr = sy-uname. How can I do it???
    Thanks,
    Amit

    Hi ,
    After the Get event ,put a check statement on node data like
    Get Pernr.
    Check pernr-pernr = sy-uname.

  • Using XPath to create nodes

    Hi,
    Obviously the main use of XPath is to query the state of an XML document... the equivalent to a "select" statement in SQL.
    DOM4J has methods that allow you to use XPath as the equivalent to "insert" statements in SQL. You can specify an XPath like "/Hello/World/Value = 3" and apply this XPath to an XML document so that it creates something like this for you:
    <Hello>
    <World>
    <Value>3</Value>
    </World>
    </Hello>
    This is actually very useful for an investment banking application that I'm working on.
    The problem with DOM4J is that it doesn't handle attributes or conditionals well. If you specify
    /Hello[@name=2]/World = 3
    I would expect
    <Hello name=2>
    <World>3</World>
    </Hello>
    to be produced. Instead, it produces
    <Hello[@name=2]>
    <World>3</World>
    </Hello>
    These are all simple examples. What I'm doing in real life is using XPath to insert nodes into a complicated XML document that already has a lot of structure. I'm only adding one or two elements to big documents.
    Is there anything at all like this available in the JDK 1.5 release. I've had a good look, and XPath looks like it's only for queries. Is this correct?

    I think this might do what you need...
    // Create a dummy XML document
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputStream bais = new ByteArrayInputStream("<test><e1/></test>".getBytes());       
    Document doc = db.parse(bais);
    // Define the XPath expression to "select" the parent element in the document       
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression xpathExpression = xpath.compile("/test/e1");    
    // Select the parent node (should probably chuck an ex if not present)       
    Node node = (Node) xpathExpression.evaluate(doc, XPathConstants.NODE);
    // Create and append the child element
    node.appendChild(doc.createElement("newElement"));
    // Convert the Document into a string
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(baos);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(source, result);
    // <?xml version="1.0" encoding="UTF-8"?><test><e1><newElement/></e1></test>
    System.out.println(baos.toString());

  • Get Node Key Multiple Items Selected  from ALV tree

    Hello Experts,
    I'm having a problem in getting Node keys for the items displayed as ALV tree.
    I'm able to get Node key, when only ONE record (Item) is selected.
    But, when I select multiple items under a Single node am not able to read(get) the node keys for all the selected items.
    I'm using the classCL_GUI_ALV_TREE.
    I have tried using the method GET_CHECKED_ITEMS, but not getting the keys.
    method GET_SELECTED_ITEM is giving node for a single item. I need it for multiple items selected.
    Thank you for your time.
    -SANGAR

    Hi,
    You need to use checkbox concept. and use method GET_CHECKED_ITEMS get selected items
    please check this tread.
    CL_GUI_ALV_TREE and Checkboxes
    aRs

  • Get node jtree without click

    hi all,
    I want get node from jtree without click, just with mouse in node.
    I look in google but dont find nothing...
    I try use listener but MousePressed dont help-me.
    thanks

    jTree1 = new JTree1(treeModel);Sorry, now
    jTree1 = new JTree(treeModel);
    MouseMotionListener mm = new MouseMotionListener(){
          public void mouseMoved(MouseEvent e) {
                System.out.println("moved "+e.getX()+" "+e.getY());
                 int selRow = jTree1.getRowForLocation(e.getX(), e.getY());
                TreePath selPath = jTree1.getPathForLocation(e.getX(), e.getY());
                if(selRow != -1) {
                                    System.out.println("mouse moved..."+selPath);
        public void mouseDragged(MouseEvent e) {
                   System.out.println("dragged "+e.getX()+" "+e.getY());
    jTree1.addMouseMotionListener(mm);
    jScrollPane1.setViewportView(jTree1);

  • GET NODE

    HELLO,
    can any one tell me what is the difference between GET NODE and GET NODE LATE ?
    Thank you very much in advance.

    HI,
    GET NODE
    This is the most important event for executable programs that use a logical database. It occurs when the logical database has read a line from the node node and made it available to the program in the work area declared using the statement NODES node.
    When you define the corresponding event block in the program, you can specify a field list if the logical database supports field selection for this node:
    GET node [FIELDS f1 f2...|.
    please check this link
    http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9aa335c111d1829f0000e829fbfe/content.htm
    GET node LATE
    This event is triggered when all of the data records for a node of the logical database have been read.
    When you define the corresponding event block in the program, you can – as with GET –specify a field list if the logical database supports field selection for this node:
    GET node LATE [..FIELDS f1 f2...|.
    Please check this link
    http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9abd35c111d1829f0000e829fbfe/content.htm
    regards
    raam

  • Retrieve XPath of a node : Urgent

    Hey guys,
    I have a small problem.
    I have an application in which a XML is displayed in browser and when user selects a node i want the XPath of that node.
    I got a handy javascript utility to do the same but it is not very efficient.
    Can anybody tellme how to do it.
    Thanks

    Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5173128

  • Iam not getting nodes in enterprise manager consol

    while iam logging from oms(enterprisemanager) not getting nodes
    iam getting the error as home agent is not started
    if i start manually in services it is not starting
    pls help me
    thanks
    kiran
    [email protected]

    I don't know about the error but alternatively you can get the list via DBA_NETWORK_ACLS and DBA_NETWORK_ACL_PRIVILEGES views.

  • XPath expression for getting nodes based on date

    Hello,
    using javax.xml.xpath.XPath (Java 5) I want to get only nodes with dates (element pubDate) greater then some provided date. What is the expression for getting, say only first two <item> nodes? Is it at all possible?
    Example XML document:
    <?xml version="1.0" encoding="utf-8"?>
    <rss version="2.0">
         <channel>
              <title>Channel title</title>
              <link>http://www.foo.bar</link>
              <description>Channel description</description>
              <item>
                   <title>title 1</title>
                   <link>http://foo.bar.org/1</link>
                   <author>author 1</author>
                   <pubDate>Thu, 15 Jun 2006 13:14:00 GMT</pubDate>
              </item>
              <item>
                   <title>title 2</title>
                   <link>http://foo.bar.org/2</link>
                   <author>author 2</author>
                   <pubDate>Thu, 15 Jun 2006 13:11:00 GMT</pubDate>
              </item>
              <item>
                   <title>title 3</title>
                   <link>http://foo.bar.org/3</link>
                   <author>author 3</author>
                   <pubDate>Thu, 14 Jun 2006 13:03:00 GMT</pubDate>
              </item>
              <item>
                   <title>title 4</title>
                   <link>http://foo.bar.org/4</link>
                   <author>author 4</author>
                   <pubDate>Thu, 13 Jun 2006 12:59:00 GMT</pubDate>
              </item>
         </channel>
    </rss>Thanks for any hints!

    I would simply assign value to a variable inside package and use the value in the expression. You can also add variable to configuration if you want to pass a value from outside. You can also add another variable to determine whether you need yesterday or
    specific date and set expression accordingly so that you expression will look like
    (DT_WSTR,30)([User::DateCategory] == "Specific Date"? @[User::Date]:(DT_WSTR, 4) DATEPART( "yyyy", DATEADD( "dd" , -1, GETDATE() ) ) + Right("0"+(DT_WSTR, 2)DATEPART( "mm", DATEADD( "dd" , -1, GETDATE() ) ),2) + Right("0"+(DT_WSTR, 2)DATEPART( "dd", DATEADD( "dd" , -1, GETDATE() ) ) ,2)) +"_*.TXT"
    DateCategory variable should be of type string
    and Date should of type date
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to get xpath of each node?

    I need to read xml data and put it on the browser. I thought frist i will get xpath of all the elements and get its value calling xpath from my another java program.
    Is there any better way to do it ? please suggest me?! In the following code the last element's number is
    getting incremented where i want that to start from [0].
    Can anyone please help me?
    My code as follows:
    book.xml
    <?xml version = "1.0" encoding= "ISO-8859-1" standalone ="no"?>  
    <book>  
        <person>  
              <first>Kiran</first>  
              <last>Pai</last>  
              <age>22</age>  
        </person>  
        <person>  
              <first>Bill</first>  
              <last>Gates</last>  
              <age>46</age>  
        </person>  
        <person>  
              <first>Steve</first>  
              <last>Jobs</last>  
              <age>40</age>  
        </person>  
    </book> 
    [/cdoe]
    My java code as follows:import java.io.File;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Stack;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    * SAX handler that creates and prints XPath expressions for each element encountered.
    * for above book.xml, my program will report
    * //book[0]
    //book[0]/person[0]
    //book[0]/person[0]/first[0]---> This segment is working fine.
    //book[0]/person[0]/last[0]
    //book[0]/person[0]/last[0]/name[0]
    //book[0]/person[0]/age[0]
    //book[0]/person[1]
    //book[0]/person[1]/first[1]->(this is wrong: should be //book[0]/person[1]/first[0])
    //book[0]/person[1]/last[0]
    //book[0]/person[1]/age[0]
    //book[0]/person[2]
    //book[0]/person[2]/first[2]-> (this is wrong: should be //book[0]/person[2]/first[0])
    //book[0]/person[2]/last[0]
    //book[0]/person[2]/age[0]

    Sorry code was in complete:
    import java.io.File;  
    import java.util.HashMap;  
    import java.util.Map;  
    import java.util.Stack;  
    import javax.xml.parsers.*;    
    import org.xml.sax.*;  
    import org.xml.sax.helpers.DefaultHandler;  
    public class SaxCreateXpath extends DefaultHandler {  
        // map of all encountered tags and their running count  
        private Map<String, Integer> tagCount;  
        // keep track of the succession of elements  
        private Stack<String> tags;  
        // set to the tag name of the recently closed tag  
        String lastClosedTag;  
         * Construct the XPath expression 
        private String getCurrentXPath() {  
            String str = "//";  
            boolean first = true;  
            for (String tag : tags) {  
                if (first){  
                    str = str + tag;  
               // first = false;  
                else 
                    str = str + "/" + tag;  
                str += "["+tagCount.get(tag)+"]";  
                first = false;  
            return str;  
        @Override 
        public void startDocument() throws SAXException {  
            tags = new Stack();  
            tagCount = new HashMap<String, Integer>();  
        @Override 
        public void startElement (String namespaceURI, String localName, String qName, Attributes atts)  
            throws SAXException  
            boolean isRepeatElement = false;  
            if (tagCount.get(localName) == null) {  
                tagCount.put(localName, 0);  
            } else {  
                tagCount.put(localName, 1 + tagCount.get(localName));  
            if (lastClosedTag != null) {  
                // an element was recently closed ...  
                if (lastClosedTag.equals(localName)) {  
                    // ... and it's the same as the current one  
                    isRepeatElement = true;  
                } else {  
                    // ... but it's different from the current one, so discard it  
                     tags.pop();  
                     tagCount.put(localName, 0);  
                 //   tagCount.put(localName, 1 - tagCount.get(lastClosedTag));  
            // if it's not the same element, add the new element and zero count to list  
            if (! isRepeatElement) {  
                tags.push(localName);  
            System.out.println(getCurrentXPath());  
            lastClosedTag = null;  
        @Override 
        public void endElement (String uri, String localName, String qName) throws SAXException {  
            // if two tags are closed in succession (without an intermediate opening tag),  
            // then the information about the deeper nested one is discarded  
            if (lastClosedTag != null) {  
                tags.pop();  
            lastClosedTag = localName;  
        public static void main (String[] args) throws Exception {  
            /*if (args.length < 1) { 
                System.err.println("Usage: SAXCreateXPath <file.xml>"); 
                System.exit(1); 
            // Create a JAXP SAXParserFactory and configure it  
            SAXParserFactory spf = SAXParserFactory.newInstance();  
            spf.setNamespaceAware(true);  
            spf.setValidating(false);  
            // Create a JAXP SAXParser  
            SAXParser saxParser = spf.newSAXParser();  
            // Get the encapsulated SAX XMLReader  
            XMLReader xmlReader = saxParser.getXMLReader();  
            // Set the ContentHandler of the XMLReader  
            xmlReader.setContentHandler(new SaxCreateXpath());  
            //String filename = "menuItems1.xml";  
            String filename = "book.xml";  
            String path = new File(filename).getAbsolutePath();  
            if (File.separatorChar != '/') {  
                path = path.replace(File.separatorChar, '/');  
                System.out.println("path="+path);  
            if (!path.startsWith("/")) {  
                path = "/" + path;  
            // Tell the XMLReader to parse the XML document  
            xmlReader.parse("file:"+path);  

  • Using xpath to get parent nodes

    hi! i�m trying to copy some elements from a xml file, and i have some problems.
    i have this file
    ?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="xslpath.xsl"?>
    <bookstore>
    <book id="0">
    <title id="pt">Harry Magico</title>
    <desc id="1">
    <price id="3">29.99</price>
    <price1 id="3">329.95</price1>
    </desc>
    <name>nome</name>
    </book>
    </bookstore>
    i�m using a xsl to copy the nodes.
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
    <xsl:copy-of select="/bookstore/book/title/ancestor-or-self::price1"/> <!--not correct-->
    </xsl:template>
    </xsl:stylesheet>
    well, if i select price1 node, what i want to get is:
    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
    <book id="0">
    <desc id="1">
    <price1 id="3">329.95</price1>
    </desc>
    </book>
    </bookstore>
    i just want copy the node without is "brothers" :) and with is parents.
    can anyone help me?

    hi! i�m trying to copy some elements from a xml file,
    and i have some problems.
    i have this file
    ?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl"
    href="xslpath.xsl"?>
    <bookstore>
    <book id="0">
    <title id="pt">Harry Magico</title>
    <desc id="1">
    <price id="3">29.99</price>
    <price1 id="3">329.95</price1>
    </desc>
    <name>nome</name>
    </book>
    </bookstore>
    i�m using a xsl to copy the nodes.
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="/">
    <xsl:copy-of
    select="/bookstore/book/title/ancestor-or-self::price
    "/> <!--not correct-->
    </xsl:template>
    l:stylesheet>
    well, if i select price1 node, what i want to get
    is:
    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
    <book id="0">
    <desc id="1">
    <price1 id="3">329.95</price1>
    </desc>
    </book>
    </bookstore>
    i just want copy the node without is "brothers" :)
    and with is parents.
    can anyone help me?right off my head, try this:
    /bookstore/book/title/desc/price1/ancestor-or-self::*

  • XSL Mapping: Get node without complete XPath

    Dear all,
    I would like to create a generic XSL mapping
    In the target structure I would like to insert the value of DOCNUM
    <xsl:template match="DOCNUM">
       <xsl:value-of select="/ORDERS/IDOC/EDI_DC40/DOCNUM" />
    </xsl:template>
    That works.
    Now, the mapping should become generic. I would like to use this for ORDERS, DELVRY and so on.
    I try tor create it this way.
       <xsl:value-of select="/../IDOC/EDI_DC40/DOCNUM" />
       <xsl:value-of select="/IDOC/EDI_DC40/DOCNUM" />
       <xsl:value-of select="/DOCNUM" />
    So I don't want to use ORDERS in the select statement.
    How to get this work for all IDOC types?
    Regards
    Chris

    just define this
    SOURCE
    <?xml version="1.0" encoding="UTF-8"?>
    <XXXXXXX>
       <IDOC BEGIN="1">
          <EDI_DC40 SEGMENT="1">
             <TABNAM>EDI_DC40</TABNAM>
             <MANDT>310</MANDT>
             <DOCNUM>0000000001021184</DOCNUM>
             <DOCREL>XX</DOCREL>
             <STATUS>XX</STATUS>
             <DIRECT>1</DIRECT>
    </EDI_DC40>
    </IDOC>
    </XXXXXXX>
    XLS
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="IDOC">
    <DOCNUM>
    <xsl:value-of select="EDI_DC40/DOCNUM" />
    </DOCNUM>
    </xsl:template>
    </xsl:stylesheet>
    RESULT
    <?xml version="1.0" encoding="UTF-8"?>
    <DOCNUM>0000000001021184</DOCNUM>
    Thanks
    Edited by: Rodrigo Alejandro Pertierra on Feb 3, 2011 2:28 PM

Maybe you are looking for