473,800 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using XPATH to extract element value.

56 New Member
I need some help to extract the LatestFillQuant ity element value using XPATH.
in Java.
I am unable to extract the value of 10000.
Please help as to what have I done wrong.?
Help appreciated.
Expand|Select|Wrap|Line Numbers
  1.  
  2. The 'Document' configNode contains the flwg:
  3.  
  4. <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
  5. <i:Interest >
  6.     <i:Generation>3</i:Generation>
  7.     <i:Extension>
  8.        <i:Active.From/>
  9.        <i:Order>
  10.         <i:Status>Confirm</i:Status>
  11.         <i:LatestFillQuantity>100</i:LatestFillQuantity>
  12.        </i:Order>
  13. </i:Extension>
  14. </i:Interest>
  15.  
  16. My Java Code 
  17.  
  18. private void extractValue(Document configNode) 
  19.     {
  20.  
  21.     XPathFactory factory = XPathFactory.newInstance();
  22.         XPath xpath = factory.newXPath();
  23.  
  24.           try{
  25.         XPathExpression expr 
  26.          = xpath.compile("//i:Order/i:LatestFillQuantity/text()");
  27.  
  28.         Object result = expr.evaluate(configNode, XPathConstants.NODESET);
  29.         NodeList nodes = (NodeList) result;
  30.         for (int i = 0; i < nodes.getLength(); i++) {
  31.             System.out.println(nodes.item(i).getNodeValue()); 
  32.         }
  33.         }catch(Exception e){
  34.             System.out.println("Sorry,this aint working");
  35.         }
  36.  
  37.  
  38.     }
  39.  
  40.  
  41.  
Jun 7 '07 #1
2 3563
luthriaajay
56 New Member
I have also tried using Namespace,but no luck.
Help appreciated.

Expand|Select|Wrap|Line Numbers
  1. private void extractValue(Document configNode) 
  2.     {
  3.         System.out.println("In extract value");
  4.         XPathFactory factory = XPathFactory.newInstance();
  5.         XPath xpath = factory.newXPath();
  6.         NamespaceContext namespace = new NamespaceContextImpl("i:", "http://www.tfs.com/common/interests");
  7.         xpath.setNamespaceContext(namespace);
  8.         try{
  9.  
  10.             //XPathExpression expr = xpath.compile("//i:Order/i:LatestFillQuantity/text()");
  11.             XPathExpression expr = xpath.compile("//i:Generation/text()");
  12.  
  13.         Object result = expr.evaluate(configNode, XPathConstants.NODESET);
  14.         NodeList nodes = (NodeList) result;
  15.         for (int i = 0; i < nodes.getLength(); i++) {
  16.             System.out.println(nodes.item(i).getNodeValue()); 
  17.         }
  18.         }catch(Exception e){
  19.             System.out.println("Sorry,this aint working");
  20.         }
  21.  
  22.  
  23.     }
  24.  
  25.  
Jun 7 '07 #2
luthriaajay
56 New Member
I have solved the above query.
Thanks,
Jun 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6826
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
0
1728
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Loan"> <xs:complexType> <xs:sequence> <xs:element name="Borrower" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="BorrID" use="required">
3
6808
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
1
2608
by: Bilal Bhutta | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or incorrect, as two examples below: <?xml version="1.0" encoding="UTF-8"?> <fileType1> <element1> <element2 attr2="xxx"> <element3>
2
2579
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or place holders, as two examples below: Example - File type 1
2
1973
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example, either C# or VB.NET, that I can try. Thank You Very Much,
1
1881
by: Pathik | last post by:
Hi All, Currently I am trying to convert one xml file into another xml file which having different format than original xml file. my input xml file is like: <?xml version="1.0" encoding="UTF-8"?> <MyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="http://www.abc.com/resources/XML/schemas/v2_0">
1
1757
by: luthriaajay | last post by:
How can I use XPATH to extract the value of Element Code in Java? I havent used this before so help appreciated. <Underlying> <Code>KGF</Code> </Underlying> Java Code:
4
10675
by: luthriaajay | last post by:
Hi, I need to use XPATH to extract the value of attribute ID in element Instrmt <?xml version="1.0" encoding="UTF-8"?> <FIXML xmlns="http://www.fixprotocol.org/FIXML-4-4"> <Order Acct="MAC" Ccy="USD" ComplianceID="C" > <Hdr SeqNum="2" Snt="2007-04-23T08:22:53" />
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10273
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7574
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.