Extract Node Values using XPATH

This may be a repeat question.
No offence meant
I am using XPATH to extract values from the nodes.
I need to extract the value of i:RequestedBy Node using XPATH
<?xml version="1.0" encoding="UTF-8"?>
<i:Interest>
<i:Status>0</i:Status>
<i:Generation>2</i:Generation>
<i:Details xsi:type="i:vanilla.details.stock">
   <i:RequestedBy>AA.MM</i:RequestedBy>
The above XML is of type Document
Document msgDoc;
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr;
Object result=null;
     try {
              expr = xpath.compile("i:Interest/i:Details/i:RequestedBy/text()");
              result = expr.evaluate(msgDoc, XPathConstants.NODESET);
           NodeList nodes = (NodeList) result;
            for (int i = 0; i < nodes.getLength(); i++) {
             System.out.println(nodes.item(i).getNodeValue());
     } catch (XPathExpressionException e1) {
     e1.printStackTrace();
                         I am getting null/
Is my XPATH correct?

I don't know if your XPath is correct or not. Your XML is not well-formed because the namespace declarations are missing. And I don't see where you set the namespace context for your XPath object; that is quite likely why it doesn't do what you want.

Similar Messages

  • Extracting node value from XPath Expression in OSB Conditional Branch

    HI All
    While using conditional branch in OSB,i only get an XPath Expression editor to set a variable used to test a condition.
    Now let's say my request is
    <Body>
    <exam:PersonSearchReq xmlns:exam="http://www.example.org">
    <exam:RequestorSSO>James</exam:RequestorSSO>
    </exam:PersonSearchReq>
    </Body>
    I write my XPath expression as :
    ./exam:PersonSearchReq/exam:RequestorSSO/text()
    Now if I test this using the tester application , insted of getting node value 'James' ,i get the entire node element ,i.e
    <exam:RequestorSSO xmlns:exam="http://www.example.org">James</exam:RequestorSSO>
    Please suggest how can i extract the text value.
    Regards,
    Chinmay

    Hi Guys
    Actually it turns out that you need to populate In-Variable to function is correctly.As soon as i entere 'body' in it,it worked fine.
    Thanks
    Chinmay

  • Want to get id's value using xpath.

    Hi all,
    I want to get id attribute's value using xpath.
    my xml file as follows:
    <book>
         <person id="1">
                <first id="2">Kiran</first>
                <last id="3">Pai
                        <name id="4">das</name>
                </last>
                <age id="5">22</age>
         </person>
         <person id="6">
                <first id="7">Bill</first>
                <last id="8">Gates</last>
                <age id="9">46</age>
         </person>
         <person id="10">
                <first id="11">Steve</first>
                <last id="12">Jobs</last>
                <age id="13">40</age>
         </person>
    </book>I want to get the id value of name. using xpath-->//book[0]/person[0]/last[0]/name[0]/[@id]..is this a valid xpath to get the id's value? 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 javax.xml.xpath.*;
    import org.w3c.dom.Document;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    public class Evaluate {
         public static void main(String[] args) {
              String xp = "//book[0]/person[0]/last[0]/name[0]"+"/[@id]";
              String id="";
          try{
               // parse the XML as a W3C Document
              DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();// Create the parser
            Document doc = docBuilder.parse(new File("book.xml"));
             XPath xpath = XPathFactory.newInstance().newXPath();
             doc.getDocumentElement().normalize();
             XPathExpression xPathExpression = xpath.compile(xp);//-->getting error here
             id=xPathExpression.evaluate(xp).toString();
             id=xPathExpression.evaluate("person");
             System.out.println("id=" +id);
                  System.out.println("xp=" +xp);
                  }catch(Exception err){
                    System.out.println("Errpr= "+ err);
    can anyone please help me ?

    No, I believe that XPath indexes begin with 1, not with zero.

  • Need to Set Node Attribute using XPath

    Hi,
    I have an XMLType coloum, I Need to Set/Update/Remove Root Node Attribute using XPath query.
    Regards,
    Rajesh

    Here you go:
           Node nameNode =
                    (Node) XPathFactory.newInstance().newXPath().evaluate(
                            "/root/name", doc, XPathConstants.NODE);
            nameNode.setTextContent("bob");

  • How to extract node value by using xpath in orchestration shape

    i want extract the node value by using xpath in expression shape in orch, then assign to variable.
    then decide shape in if branch im using check condition based nodevalue .
    str = xpath(Message_3, ("string(/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_ProjectRNd2.Schema3']/*[local-name()='no' and namespace-uri()=''])"));
    but i got below error:
    xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'BizTalk_Server_ProjectRNd2.BizTalk_Orchestration1(f3c581d3-049f-8a8a-9316-fc1235b03f99)'.
    The service instance will remain suspended until administratively resumed or terminated. 
    If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
    InstanceId: 020779be-713d-408c-9ff4-fd1462c2e52c
    Shape name: Expression_1
    ShapeId: b865a3e1-7ebe-410d-9f60-8ad2139ad234
    Exception thrown from: segment 1, progress 10
    Inner exception: There is an error in the XML document.
    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
    The following is a stack trace that identifies the location where the exception occured
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
       at Microsoft.XLANGs.Core.Part.XPathLoad(Part sourcePart, String xpath, Type dstType)
       at BizTalk_Server_ProjectRNd2.BizTalk_Orchestration1.segment1(StopConditions stopOn)
       at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
    Additional error information:
            <no xmlns=''> was not expected.
    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Read_string()
    The following is a stack trace that identifies the location where the exception occured
       at System.Xml.Serialization.XmlSerializationPrimitiveReader.Read_string()
       at System.Xml.Serialization.XmlSerializer.DeserializePrimitive(XmlReader xmlReader, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)

    Hi,
    as per your  code i got below error 
    Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'BizTalk_Server_ProjectRNd2.BizTalk_Orchestration1(f3c581d3-049f-8a8a-9316-fc1235b03f99)'.
    The service instance will remain suspended until administratively resumed or terminated. 
    If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
    InstanceId: f5fffb05-e6d6-4765-83da-4e6c9696dd8a
    Shape name: Expression_1
    ShapeId: b865a3e1-7ebe-410d-9f60-8ad2139ad234
    Exception thrown from: segment 1, progress 10
    Inner exception: There is an error in the XML document.
    Exception type: InvalidOperationException
    Source: System.Xml
    Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
    The following is a stack trace that identifies the location where the exception occured
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializat
    this is my schema:
      <?xml version="1.0" encoding="utf-16"
    ?>
    <xs:schema xmlns="http://BizTalk_Server_ProjectRNd2.Schema3" xmlns:b="http://schemas.microsoft.com/BizTalk/2003"
    xmlns:ns0="https://BizTalk_Server_ProjectRNd2.PropertySchema" targetNamespace="http://BizTalk_Server_ProjectRNd2.Schema3" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
    <xs:appinfo>
    <b:imports>
      <b:namespace
    prefix="ns0" uri="https://BizTalk_Server_ProjectRNd2.PropertySchema" location=".\PropertySchema.xsd"
    />
      </b:imports>
      </xs:appinfo>
      </xs:annotation>
    <xs:element name="Root">
    <xs:annotation>
    <xs:appinfo>
    <b:properties>
      <b:property
    name="ns0:no" xpath="/*[local-name()='Root' and namespace-uri()='http://BizTalk_Server_ProjectRNd2.Schema3']/*[local-name()='no' and namespace-uri()='']"
    />
      </b:properties>
      </xs:appinfo>
      </xs:annotation>
    <xs:complexType>
    <xs:sequence>
      <xs:element
    name="no" type="xs:string" />
      <xs:element
    name="name" type="xs:string" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:schema>

  • Failing to extract xml value using Jdom & Xpath

    I have a method (getSingleNodeValue()) which when passed an xpatch expression will extract the value of the specified element in the xml document refered to in 'doc'. Assume doc at this point has been initialised as shown below and xmlInput is the buffer containing the xml content.
        SAXBuilder     builder          =     null;
        Document     doc          =     null;
        XPath          xpathInstance     =      null;
        doc     = builder.build(new StringReader(xmlInput));When i call the method, i pass the following xpath xpression
        /TOP4A/PERLODSUMDEC/TINPLD1/text()Here is the method. It basically just takes an xml buffer and uses xpath to extract the value:
        public static String getSingleNodeValue(String xpathExpr) throws Exception{
             Text list = null;
             try {
                  xpathInstance = XPath.newInstance(xpathExpr);
                  list = (Text) xpathInstance.selectSingleNode(doc);
             } catch (JDOMException e) {
                  throw new Exception(e);
             }catch (Exception e){
                  throw new Exception(e);
             return list==null ? "?" : list.getText();
        }The above method always returns "?" i.e. nothing is found so 'list' is null.
    The xml document it looks at is
        <TOP4A xmlns="http://www.testurl.co.uk/enment/gqr/3232/1">   
          <HEAD>
            <Doc>ABCDUK1234</Doc> 
          </HEAD>   
          <PERLODSUMDEC>
            <TINPLD1>10109000000000000</TINPLD1>
          </PERLODSUMDEC>
        </TOP4A>The same method works with other xml documents so i am not sure what is special about this one. There is no exception so the xml is valid xml. Its just that the method always sets 'list' to null. Any ideas?
    Edit
    Here is a running program testing the above:
        import org.jdom.*;
        import org.jdom.input.*;
        import org.jdom.xpath.*;
        import java.io.IOException;
        import java.io.StringReader;
        public class XpathTest {
             public static String getSingleNodeValue(String xpathExpr, String xmlInput) throws Exception{
                 Text list = null;
                  SAXBuilder  builder           =   null;
                  Document    doc                    =   null;
                  XPath       xpathInstance   =   null;
                 try {
                      builder     = new SAXBuilder();     
                      doc          = builder.build(new StringReader(xmlInput));
                     xpathInstance = XPath.newInstance(xpathExpr);
                     list = (Text) xpathInstance.selectSingleNode(doc);
                 } catch (JDOMException e) {
                     throw new Exception(e);
                 }catch (Exception e){
                     throw new Exception(e);
                 return list==null ? "Nothing Found" : list.getText();
             public static void main(String[] args){
                  String xmlInput1 = "<TOP4A xmlns=\"http://www.testurl.co.uk/enment/gqr/3232/1\"><HEAD><Doc>ABCDUK1234</Doc></HEAD><PERLODSUMDEC><TINPLD1>10109000000000000</TINPLD1></PERLODSUMDEC></TOP4A>";
                  String xpathExpr = "/TOP4A/PERLODSUMDEC/TINPLD1/text()";
                  XpathTest xp = new XpathTest();
                  try {
                       System.out.println(xp.getSingleNodeValue(xpathExpr, xmlInput1));
                  } catch (Exception e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
        }When i run the above, the output is
        Nothing foundEdit
    I have run some further testing and it appears that if i remove the namespace url it does work. Not sure why yet. Is there any way i can tell it to ignore the namespace?
    Edited by: ziggy on Sep 3, 2011 4:57 PM

    ziggy wrote:
    <TOP4A xmlns="http://www.testurl.co.uk/enment/gqr/3232/1">   
    <HEAD>
    <Doc>ABCDUK1234</Doc> 
    </HEAD>   
    <PERLODSUMDEC>
    <TINPLD1>10109000000000000</TINPLD1>
    </PERLODSUMDEC>
    </TOP4A>
    It works fine, the problem is not with namespace, it is with url have given.
    Editing:
    Found a way to say the program to ignore namespace.
    You have to use Xpath.addNamespace(prefix,uri), and pass the prefix to your pattern string.
    If not clear refer the below code:
    import org.jdom.*;
        import org.jdom.input.*;
        import org.jdom.xpath.*;
        import java.io.IOException;
        import java.io.StringReader;
        public class XpathTest {
             public static String getSingleNodeValue(String xpathExpr, String xmlInput) throws Exception{
                 Text list = null;
                  SAXBuilder  builder           =   null;
                  Document    doc                    =   null;
                  XPath       xpathInstance   =   null;
                 try {
                      builder     = new SAXBuilder();     
                      doc          = builder.build(new StringReader(xmlInput));
                     xpathInstance = XPath.newInstance(xpathExpr);
                        xpathInstance.addNamespace("ns","http://www.testurl.co.uk/enment/gqr/3232/1");
                     list = (Text) xpathInstance.selectSingleNode(doc);
                 } catch (JDOMException e) {
                     throw new Exception(e);
                 }catch (Exception e){
                     throw new Exception(e);
                 return list==null ? "Nothing Found" : list.getText();
             public static void main(String[] args){
                  String xmlInput1 = "<TOP4A xmlns=\"http://www.testurl.co.uk/enment/gqr/3232/1\"><HEAD><Doc>ABCDUK1234</Doc></HEAD><PERLODSUMDEC><TINPLD1>10109000000000000</TINPLD1></PERLODSUMDEC></TOP4A>";
                  String xpathExpr = "/ns:TOP4A/ns:PERLODSUMDEC/ns:TINPLD1/text()";
                  XpathTest xp = new XpathTest();
                  try {
                       System.out.println(xp.getSingleNodeValue(xpathExpr, xmlInput1));
                  } catch (Exception e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
        }Edited by: 833545 on Sep 8, 2011 11:35 PM

  • Issue with extracting node values of an XMLElement with multiple namespaces

    I have created a Table with XMLType Column
    CREATE TABLE xmlNode
    ( ID numeric(10) primary key,
    DATA XMLType);
    Then inserted one row
    INSERT INTO xmlNode(ID, DATA) VALUES(1, '<lineItemElement orderLineItemID="12323" transactionType="New" xmlns="http://rcss.bell.ca/schema/lineitemmessages">
    <rcss:catalogeID xmlns:rcss="http://rcss.bell.ca/schema/PartnerBatch">3234</rcss:catalogeID>
    <rcss:venueID xmlns:rcss="http://rcss.bell.ca/schema/PartnerBatch">345345</rcss:venueID>
    <rcss:startDate xmlns:rcss="http://rcss.bell.ca/schema/PartnerBatch">2007-09-10T00:00:00Z</rcss:startDate>
    <rcss:endDate xmlns:rcss="http://rcss.bell.ca/schema/PartnerBatch">2007-09-10T00:00:00Z</rcss:endDate>
    <rcss:contact contactID="234234" xmlns:rcss="http://rcss.bell.ca/schema/PartnerBatch">
    <rcss:address>
    <rcss:streetAddress1>?asdsd</rcss:streetAddress1>
    <rcss:streetAddress2>?sdss</rcss:streetAddress2>
    <rcss:city>?ddf</rcss:city>
    <rcss:province>?sdcfsdcf</rcss:province>
    <rcss:country>sds</rcss:country>
    <rcss:postalCode>1121332</rcss:postalCode>
    </rcss:address>
    </rcss:contact>
    </lineItemElement>')
    Then i ran:
    SELECT
    extractValue(data,'/lineItemElement/rcss:catalogeID','xmlns=http://rcss.bell.ca/schema/lineitemmessages, xmlns:rcss=http://rcss.bell.ca/schema/PartnerBatch')
    from xml where id=1
    There is nothing returned.
    Please advise how could I get the node value when there is namespace?
    I know how to extract values if there is one namespace but i'm not able to extract values if there are two namespaces.
    Any help is appreciable!!
    Thanks in Advance.

    I fixed that problem too. What I thought was a singleton was actually a repeating element. I needed to be able to "multiply" the repeating node for the main node, but I couldn't find a concise way of doing this in SQL. So instead I did it in with two loops.
    FOR rec IN (
    SELECT
         extractvalue(value(e), 'surchargeEntry/company',p_namespace) company
         ,extractvalue(value(e), 'surchargeEntry/surchargeType',p_namespace) surcharge_type
         ,extractvalue(value(e), 'surchargeEntry/shortDescription',p_namespace) short_description
         ,extractvalue(value(e), 'surchargeEntry/longDescription',p_namespace) long_description
         ,e.column_value surcharge_entry_xml
         FROM TABLE(xmlsequence(extract(p_xml, 'surchargeInquiryResponse' ||
         '/surchargeAttributes/surchargeEntry'
                                                                                    ,p_namespace))) e
    ) LOOP
    FOR rec_country IN (
    SELECT
         extractvalue(value(c), 'country/originationCountry',p_namespace) origination_country
         ,extractvalue(value(c), 'country/destinationCountry',p_namespace) destination_country
         FROM TABLE(xmlsequence(extract(rec.surcharge_entry_xml, 'surchargeEntry/country',p_namespace))) c
    LOOP
    nafta_fee_obj.append_surcharge_entry_data(
              v_arr
              ,r_surcharge_entry(
              rec.company
              ,rec.surcharge_type
              ,rec.short_description
              ,rec.long_description
              ,rec_country.origination_country
              ,rec_country.destination_country
    END LOOP;
    END LOOP;
    I populate a collection, which is easy to pass around between routines. I can easily convert the collection to a ref cursor, and index-by array, comma-delimited string, etc.
    Apparently, the namespace is required in SQL, but not in staright PL/SQL.
    I've also noticed that the docs say xmltype() has all these member functions, but when I try to use some of them, I get an error that it's undefined. Like getNumVal(). There are some functions I can use in SQL, or PL/SQL, but not vice-versa.
    - Dan Clamage

  • How to Edit the xml node value using flex from the front end UI

    Hi All,
    I am having a use case with flex 4.6
    1> To read the external xml file
    2> Display the tree structure in the front end UI
    3> Edit the node values of the xml file from the front end UI and save it back
    How to go about the above use case, any blogs or links on the above case will be help
    Thanks,
    Alok

    Check this is example:
    http://blog.flexexamples.com/2009/07/23/deleting-nodes-from-an-xml-object-in-flex/

  • Selcect/ update attribute value using xpath navigator/ linq to xml

    Hi Folks,
    below is my xml string and the highlighted bold attribute value needs to update. Since this element contains prefix im not able to select teh particular element. if i remove the prefixx im able to select but i need to keep prefix.
        <IOP:MtvnSvcReq xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:IOP="mtvnCWExternInteropReq" xmlns:IOP1="mtvnExtInteropReqData" xmlns:PR1="mtvnPRInteropReqData">
                              <IOP:Svc>
                                                 <IOP1:PR1>
                                                       <PR1:PRExternSSOReqData>
    <PR1:UserId>abcd</PR1:UserId>
                                                       </PR1:PRExternSSOReqData>
                                                 </IOP1:PR1>
                                </IOP:Svc>
                        </IOP:MtvnSvcReq>
    Thanks 

    Hi Pulikk,
    Do you mean you want  to change the attribute value(abcd)? If so,
    Please try the following code, i tested on my side, it changed successfully.
    //Here is the variable with which you assign a new value
    string newValue = string.Empty;
    XDocument objDoc = XDocument.Load(@"yourdata.xml");
    XNamespace IOP = "mtvnCWExternInteropReq";
    XNamespace IOP1 = "mtvnExtInteropReqData";
    XNamespace PR1 = "mtvnPRInteropReqData";
    foreach (var node in objDoc.Descendants(PR1 + "UserId"))
    node.Value = newValue;
    objDoc.Save(@"yourdata.xml");
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Fetching xml node nth value using Xpath

    HI Experts ,
    with reference to below question, i have one more doubt.
    https://social.msdn.microsoft.com/Forums/en-US/f894e5e2-8926-4604-9171-616da3f00cd7/xpath-to-fetch-value-in-flatfile-schema?forum=biztalkgeneral
    I used below xpath to fetch nth value of full repeating message nodes
    indexStr = System.Convert.ToString(index);DATE=xpath(In_FF, "string(//*[local-name() = 'Details']["+indexStr+"])/*[local-name()='DATE'])");index=index + 1;
    and i got below error, can any help me in this?
    Exception thrown from: segment 2, progress 43
    Inner exception: 'string(//*[local-name() = 'Details'][1])/*[local-name()='DATE'])' has an invalid token.
    Exception type: XPathException
    Source: System.Xml
    Target Site: MS.Internal.Xml.XPath.AstNode ParseXPathExpresion(System.String)
    The following is a stack trace that identifies the location where the exception occured

    your XPATH expression is WRONG.
    it should be
    DATE=xpath(In_FF,
    "string(//*[local-name() = 'Details']["+indexStr+"]/*[local-name()='DATE'])");
    There is NO ")" after ["+indexStr+"].
    The more reliable way is to use a string variable and use the System.String.Format() call as below
    xPathExpr = System.String.Format("string(//*[local-name() = 'Details'][{0}]/*[local-name()='DATE'])", index);
    DATE=xpath(In_FF, xPathExpr);
    The "invalid token" is because of the mismatched ")" in your XPATH Expression.
    Regards.

  • How to add node value using org.w3c.dom.Document?

    Hi ,
    I'm using org.w3c.dom.Document to deal with xml files. I could successfully add nodes , and their attributes. However I could not add a value of the node. (e.g. <myNode>I couldn't add this value</myNode>)
    does anyone know how to deal with this?
    I tried subNode.setNodeValue("the value i can't add"); whereas the subNode is an instance of org.w3c.dom.Node... i know this is interface i of course used the concrete class
    org.apache.crimson.tree.ElementNode
    but when I used the subNode.getNodeValue() i simply got null?
    can u plz help me?
    thanks in advance

    Reading the API documentation for the Node interface might help. At least you wouldn't be surprised when the results are exactly what the documentation says they will be.
    What would really help would be forgetting the idea that an Element can have a value. Text nodes have values, though, so create a Text node and make it the child of the Element node.

  • XMLSearch / case in-sensitive search in a text node value with XPATH

    Hi everyone,
    I was aggregating some XML files and queries for a search
    engine. It is pretty easy with coldfusion XML functions BUT ....
    I was looking around XMLSearch to do a simple text search
    into nodes and I am stuck with it.
    with something like that :
    selectedElements = XmlSearch(myxmldoc,
    '(/directory/user[contains(.,"#form.firstName#")])');
    Without loop all the XML elements, I cannot put firstName
    text nodes to lower-case, do a simple search into the directory and
    get user entries.
    Is it possible to do with XPATH something like that :
    selectedElements = XmlSearch(myxmldoc,
    '(/directory/user[contains(lower-case(.),lower-case("#form.firstName#"))])');
    Thanks for your help.

    When Do you think coldfusion will implement Xpath functions
    as
    http://www.w3schools.com/xpath/xpath_functions.asp
    ????

  • Using XPATH to extract value.

    I need some help to extract the LatestFillQuantity element value using XPATH.
    in Java.
    I am unable to extract the value of 10000.
    Please help as to what have I done wrong.?
    The Document configNode contains the flwg:
    <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
    <i:Interest >
         <i:Generation>3</i:Generation>
         <i:Extension>
            <i:Active.From/>
            <i:Order>
              <i:Status>Confirm</i:Status>
              <i:LatestFillQuantity>100</i:LatestFillQuantity>
            </i:Order>
    </i:Extension>
    </i:Interest>
    My Java Code
    private void extractValue(Document configNode)
         XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
              try{
             XPathExpression expr
              = xpath.compile("//i:Order/i:LatestFillQuantity/text()");
             Object result = expr.evaluate(configNode, XPathConstants.NODESET);
             NodeList nodes = (NodeList) result;
             for (int i = 0; i < nodes.getLength(); i++) {
                 System.out.println(nodes.item(i).getNodeValue());
             }catch(Exception e){
                  System.out.println("Sorry,this aint working");
         }

    The nodes being parsed are namespace prefixed.
    To parse a namespace node with the JDK 5.0 javax.xml.xpath package, set the NamespaceContext on the XPath object.
    An implementation of NamespaceContext with a single prefix corresponding to a namespace uri:
    public class NamespaceContextImpl implements NamespaceContext{
    public String uri;
    public String prefix;
    public NamespaceContextImpl(){}
    public NamespaceContextImpl(String prefix, String uri){
         this.uri=uri;
         this.prefix=prefix;
    public String getNamespaceURI(String prefix){
       return uri;
    public void setNamespaceURI(String uri){
       this.uri=uri;
    public String getPrefix(String uri){
       return prefix;
    public void setPrefix(String prefix){
       this.prefix=prefix;
    public Iterator getPrefixes(String uri){return null;}
    }

  • Using XPath for DOM traversal

    This question falls into the category of 'I know it's possible, I just need to find the idom in Java'.
    I'm coming from a MSFT world were the DOM-centric model of XML processing makes heavy use of XPATH for node selection. Basically using the method element.selectNodes(XPathExpresson) allows one to quickly extract the relevant subset of the parsed tree in the DOM as a nodeList. I've become accustomed to using XML for all strucutured storage that doesn't require a full database.
    The W3C DOM Level 3 spec supports evaluateExpression() for this purpose, but I can't believe that Java developers are still using tree traversal waiting for the spec to be implemented. I suppose that I could use getNodesByTagName(), but this is a chainsaw, and I need a scalpel. Anyway, I'm trying to figure out how, exactly, this gets done in Java.
    I figure the following are possibilities:
    1) It's in JAXP and I missed it
    2) One or more of the XML parsers supports XPATH as an extention
    3) There's a common package that sits on top of the DOM Document.
    4) There's a standard way to apply and XSLT methods to the DOM document
    5) Something I've never thought of.
    This is a generalized problem for me, so I can't rely on object serialization, Java-XML data mapping, etc. Any guidance would be greatly appreciated.

    I've written a Config file reader for XML in java,
    and it extracts values using XPath. This is
    some of the code you'll need:
    imports:
    import javax.xml.transform.TransformerException;
    import org.w3c.dom.*;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.apache.xerces.parsers.DOMParser;
    import org.apache.xpath.XPathAPI;
    import org.apache.xpath.objects.*;
    Document doc=....;
    * returns a single DOM Node from the config file.
    public Node getNode(String xpath) throws ConfigException {
    try {
    return XPathAPI.selectSingleNode(doc, xpath);
    } catch (TransformerException e) {
    throw new ConfigException("Can't find '"+xpath+"' ("+e.getMessage()+")");

  • C++ sample code using XPATH

    Need to navigate an XML and extract xml nodes using XPATH expressions in C++ Application.
    Please send us a C++ code sample using Oracle 9.2.0.3 XPATH API functions to extract an XML using XPATH expression.
    Thanks
    Shiva

    Hi,
    Where i can find this path "$XDK_HOME\xdk\demo\c\xslt"
    thanks in advance
    shashi.

Maybe you are looking for

  • Best Practice for closing a blocking connection to the database.

    Background: Using toplink/eclipselink to manage the the connection to the database. We support 3 databases, Oracle, Mysql, and MSSQL. We host the an application locally (SAAS) and we also distribute it to our clients so they can run it on premise. Pr

  • Form Created in InDesign doesn't open in FormsCentral

    I'm relatively new to FormsCentral and I'm having a difficult time getting it work. I was supplied a form from my client. I took the PDF form into InDesign CS6 because there was some other changes that needed to be made. I added all the form fields a

  • ALV GRID update internal table

    Hi all, I have an internal table display in a ALV GRID. Only one column is editable. When I change the field value, ALV GRID display the change, but when I click on refresh return the old value. I've checked in DEBUG mode and when I click on refresh

  • Cannot start Visual Studio 2013 Community edition

    Windows 7 on a 64-bit PC... Downloaded the installer vs_community.exe for Visual Studio 2013 with Update4 yesterday and ran it. It took about 1 hour and 20 minutes. At the end the installer reported the web deployment function could not be found/inst

  • Qosmio G30-201 HD-DVD cant play- Cannot display video on ext device?

    Hi, I am trying to play Heroes Season 1 HD DVD on my G30-201, and get a message ' Cannot display video on external device ' but there is NO external device - I am firstly trying to display it on the G30 screen. I would like to play it out through HDM