Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8838473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:00:19+00:00 2026-06-14T10:00:19+00:00

I have the follwing XML file – <?xml version=1.0 encoding=UTF-8?> <BatchOrders xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <BatchHeader> <ServiceProvider>123456789</ServiceProvider>

  • 0

I have the follwing XML file –

<?xml version="1.0" encoding="UTF-8"?>
<BatchOrders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <BatchHeader>
     <ServiceProvider>123456789</ServiceProvider>
     </BatchHeader>
   <OrderDetails>
     <MessageType>HelloWorld</MessageType>
  <IssueDateTime>22/01/2012 00:00:00</IssueDateTime> 
  <receivedDateTime>22/01/2012 00:00:00</receivedDateTime> 
     <Status>TestStatus</Status>
  </OrderDetails>
  </BatchOrders>

I want to read in the contents and set them to fields I have created. So I have the following code below (not some is omitted – I have just included what I think I need to show. The below is in a test class which I have created – I also have a writer as part of this class that writes an XML File fine to disk as I expect. The problem I am facing is reading the file above and displaying the contents read to the Console just for now.

File        myFileRead = null;
FileReader  myFileReader = null;

try {

myFileRead    = new File("C:/Path/myfile.xml");
myRecord = new myRecord();
myFileReader = new FileReader(myFileRead);

myXPathReader reader = new myXPathReader(myFileReader);

while (reader.hasNext())
{
       record = reader.next();

//prints out then to cosole
}

So from above I have the myRecord class where I have the getters/setters for e.g ServiceProvider, etc. I also then have a class for myXpathReader which does the following:

    private Document document;
    private List     batchorders;
    private Iterator iterator;

    public myXPathReader (Reader myFileReader)
    throws Exception 
    {
        SAXBuilder builder = new SAXBuilder();
        document = builder.build(myFileReader);      

        batchorders = new JDOMXPath("//BatchOrders").selectNodes(document);

        iterator = batchorders.iterator();
    }

   public int getSize() { return batchorders.size(); }

   public boolean hasNext() { return iterator.hasNext(); }


   public myRecord next() 
    throws Exception {

        Element element = (Element) iterator.next();


        myRecord record = new myRecord();

      record.setServiceProvider((new JDOMXPath("./ServiceProvider").stringValueOf(element)));
      //Some more sets ans close class etc...

Now if I debug the code and after the element on iterator.next I can see the file contents have being read in correctly. But on my console the ServiceProvider value and in fact all the values are getting set to empty string “”. Am I doing something incorrect on the JDOMXPath in order to pull the value from the XML?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:00:20+00:00Added an answer on June 14, 2026 at 10:00 am

    In your example XML ServiceProvider is not a child of BatchOrders, there’s another level (BatchHeader) in between. So your second XPath expression should probably be

    BatchHeader/ServiceProvider
    

    instead of ./ServiceProvider

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML file: <?xml version=1.0 encoding=utf-8?> <SearchResults:searchresults xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.zillow.com/static/xsd/SearchResults.xsd /vstatic/279989c5e93d519f8d8f23d3f6cac661/static/xsd/SearchResults.xsd xmlns:SearchResults=http://www.zillow.com/static/xsd/SearchResults.xsd>
Lets say I have the following XML file: <?xml version=1.0 encoding=utf-8?> <Customers xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=Customer.xsd>
I have following XML file: <?xml version=1.0 encoding=UTF-8?> <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:jaxrs=http://cxf.apache.org/jaxrs xmlns:context=http://www.springframework.org/schema/context xmlns:cxf=http://cxf.apache.org/core
I have the following xml file: <ArrayOfX xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <X> <Name>Name1</Name> <ArrayOfY> <Y> <Member1>1</Member1>
I have the following XML layout file, HELPME.XML <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
i have following xml file as input .... <?xml version=1.0 encoding=ISO-8859-1?> <T0020 xsi:schemaLocation=http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd
I have following xml: <xs:schema attributeFormDefault=unqualified elementFormDefault=qualified xmlns=http://www.testuri.org targetNamespace=http://www.testuri.org xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:element name=Price> <xs:complexType> <xs:sequence>
I have the following xml file <kml xmlns=http://www.opengis.net/kml/2.2 xmlns:gx=http://www.google.com/kml/ext/2.2 xmlns:kml=http://www.opengis.net/kml/2.2 xmlns:atom=http://www.w3.org/2005/Atom> <Placemark> <name>Simple placemark</name>
I have the following XML file:- <?xml version=1.0 encoding=UTF-8?> <viewentries> <viewentry position=1> <entrydata columnnumber=0>
I have the following invalid XML file: <?xml version=1.0 encoding=utf-8 ?> <Page num=1 crop_box=0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.