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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:47:47+00:00 2026-06-13T21:47:47+00:00

I’m using SimpleXML (Java) and I’m trying to get a List of objects based

  • 0

I’m using SimpleXML (Java) and I’m trying to get a List of objects based on the value of one of the siblings of the list.

So, here’s my XML:

<xml>
  <metadata>
    <resources>

      <resource>
        <ittype>Service_Links</ittype>
        <links>
          <link>
            <path>http://www.stackoverflow.com</path>
            <description>Stack Overflow</description>
          </link>
          <link>
            <path>http://www.google.com</path>
            <description>Google</description>
          </link>
        </links>
      </resource>

      <resource>
        <ittype>Article_Links</ittype>
        <links>
          ...
        </links>
      </resource>

      ...

    </resources>
  </metadata>
</xml>

What I am trying to do is create a SimpleXML-annotation using XPath in order to get a List of all of the “links” where the list’s sibling “ittype” equals “Service_Links”.

So, for example, this works but only if I’m trying to statically get the 1st “resource”-node (as opposed to dynamically getting the “resource”-node based on what it’s sibling “ittype” is:

@ElementList(name="links")
@Path("metadata/resources[1]/resource")
public List<Link> link;

I’ve tried so many ways to format the xpath to dynamically find the “resource”-node I want that I couldn’t possibly list them all here; however, this is one example I’ve tried that seems to me it should work; no clue what I’m doing wrong…

@ElementList(name="links")
@Path("metadata/resources[resource/ittype='Service_Links']/resource")
public List<Link> link;

I’ve googled a ton, including here on SO, and just can’t find much very similar; and what I did find, didn’t translate well enough for me to spot what I need to do. For example, this SO didn’t seem to work even though it’s pretty similar.


UPDATE #1 (8OCT @ 12:38pm)

Per feedback, I have tried this:

@ElementList
@Path("metadata/resources/resource[ittype='Service_Links']")
public List<Link> link;

No dice:
org.simpleframework.xml.core.PathException: Invalid index for path ‘metadata/resources/resource[ittype=’Service_Links’]’ in field ‘links’

  • 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-13T21:47:48+00:00Added an answer on June 13, 2026 at 9:47 pm

    I never got SimpleXml to implement this style of XPath; from reading through their docs more thoroughly, it looks like they haven’t implemented this XPath feature yet.

    So I settled on a different XML-parsing strategy here: https://stackoverflow.com/a/13236117/483257

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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 have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.