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

  • Home
  • SEARCH
  • 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 6611433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:58:08+00:00 2026-05-25T19:58:08+00:00

I’m trying to parse a XML using Apache Commons JXPath. But for some reason,

  • 0

I’m trying to parse a XML using Apache Commons JXPath. But for some reason, its not able to identify the child nodes after the xml is being parsed. Here’s the sample code :

private static void processUrl(String seed){
    String test = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:openSearch=\"http://a9.com/-/spec/opensearchrss/1.0/\" xmlns:gd=\"http://schemas.google.com/g/2005\" xmlns:yt=\"http://gdata.youtube.com/schemas/2007\"><id>http://gdata.youtube.com/feeds/api/videos</id><logo>http://www.youtube.com/img/pic_youtubelogo_123x63.gif</logo><link rel=\"alternate\" type=\"text/html\" href=\"http://www.youtube.com\"/><author><name>YouTube</name><uri>http://www.youtube.com/</uri></author><generator version=\"2.1\" uri=\"http://gdata.youtube.com\">YouTube data API</generator><openSearch:totalResults>144</openSearch:totalResults><entry><id>http://gdata.youtube.com/feeds/api/videos/P1lDDu9L5YQ</id><published>2010-09-20T17:41:38.000Z</published><updated>2011-09-18T22:15:38.000Z</updated><category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://gdata.youtube.com/schemas/2007#video\"/><link rel=\"alternate\" type=\"text/html\" href=\"http://www.youtube.com/watch?v=P1lDDu9L5YQ&amp;feature=youtube_gdata\"/></entry></feed>";
    Document doc = null;
    try{
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        ByteArrayInputStream bais = new ByteArrayInputStream(test.toString().getBytes("UTF8"));
        doc = builder.parse(bais);
        bais.close();

        JXPathContext ctx = JXPathContext.newContext(doc);
        List entryNodes = ctx.selectNodes("/feed/entry");
        System.out.println("number of threadNodes " + entryNodes.size());
        int totalThreads = 0;
        for (Object each : entryNodes) {
            totalThreads++;
            Node eachEntryNode = (Node) each;
            JXPathContext msgCtx = JXPathContext.newContext(eachEntryNode);
            String title = (String) msgCtx.getValue("title");
        }
    }catch (Exception ex) {
        ex.printStackTrace();
    }
}

I’ve used JXPath earlier and never had any issues. I debugged the document object,it doesn’t seemed to have the child node () for . All I’m able to see is the root element. I also tried DOMParser without any luck.

DOMParser parser = new DOMParser();
        Document doc = (Document) parser.parseXML(new ByteArrayInputStream(sb0.toString().getBytes("UTF-8")));

I’ll appreciate if someone can provide pointers to this isuse.

  • 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-05-25T19:58:08+00:00Added an answer on May 25, 2026 at 7:58 pm

    This issue has to do with how JXPath handles default namespaces, which closely follows the XPath 1.0 specification. This also explains why it worked after you removed the default namespace http://www.w3.org/2005/Atom. In order to get it to work with the default namespace you can do the following:

    JXPathContext ctx = JXPathContext.newContext(doc.getDocumentElement());
    // Register the default namespace, giving it a prefix of your choice
    ctx.registerNamespace("myfeed", "http://www.w3.org/2005/Atom");
    
    // Now query for entry elements using the registered prefix
    List entryNodes = ctx.selectNodes("myfeed:entry");
    

    For more information on the issue see the following links.

    http://markmail.org/message/7iqw4bjrkwerbh46

    Make jxpath namespace aware

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put

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.