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 8321911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:11:15+00:00 2026-06-08T23:11:15+00:00

So I have an XML file here, and I want to get a value

  • 0

So I have an XML file here, and I want to get a value from it using XPath. The file in question is an XML file in a zip that you can download here:

I believe that it’s valid XML.

My current goal is to parse out the last (newest) LMP_PRC value in the document.

My current code looks like this and returns an empty string every time:

XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr =
  xpath.compile("//m:OASISReport/m:MessagePayload/m:RTO/m:REPORT_ITEM[3]/m:REPORT_DATA[/m:DATA_ITEM='LMP_PRC'][last()]/m:VALUE/text()") ;
String result = (String) expr.evaluate(doc, XPathConstants.STRING);

The m:REPORT_ITEM[3] has been an area of confusion for me so I’ve tried it with just about every number and have had no luck with it.

  • 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-08T23:11:18+00:00Added an answer on June 8, 2026 at 11:11 pm

    The m:REPORT_ITEM[3] just means the 3rd one that matches. You’re not getting any matches because of:

    m:REPORT_DATA[/m:DATA_ITEM='LMP_PRC'][last()]
    

    You want the relative path from there, not the absolute path:

    m:REPORT_DATA[m:DATA_ITEM='LMP_PRC'][last()]
    

    So the whole thing would look like:

    //m:OASISReport/m:MessagePayload/m:RTO/m:REPORT_ITEM[3]/m:REPORT_DATA[m:DATA_ITEM='LMP_PRC'][last()]/m:VALUE/text()
    

    The other thing to deal with is the namespace resolution. For a good summary of what is happening in your case, see http://blog.davber.com/2006/09/17/xpath-with-namespaces-in-java/. So you should add something like:

    private static NamespaceContext getNamespaceContext() {
        NamespaceContext namespaceContext = new NamespaceContext() {
            public String getNamespaceURI(String prefix) {
                String uri = null;
                if (prefix == null) {
                    throw new IllegalArgumentException("No prefix provided!");
                } else if(prefix.equals("m")) {
                    uri = "http://oasis.caiso.com/mrtu-oasis/xsd/OASISReport.xsd";
                }
                return uri;
            }
    
            @SuppressWarnings("rawtypes")
            @Override
            public Iterator getPrefixes(String namespaceURI) {
                // TODO Auto-generated method stub
                return null;
            }
    
            @Override
            public String getPrefix(String namespaceURI) {
                // TODO Auto-generated method stub
                return null;
            }
        };
    
        return namespaceContext;
    }
    

    And then use that method to set the namespace context on your xpath object:

    xpath.setNamespaceContext(getNamespaceContext());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that I'm trying to read from here , and
I have an XML file that is very long, but here is a shot
I have configured the properies file in JBoss AS 6 using properties-service.xml . here
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have a datagridview that displays data from an XML file. The DGV is
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
I have an XML file from which I am parsing some content to display
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I want to read XML data using XPath in Java, so for the information
I have a xml file on which I want to make a query to

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.