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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:04:27+00:00 2026-05-16T20:04:27+00:00

Somewhat related to How to convert XML to java.util.Map and vice versa , only

  • 0

Somewhat related to How to convert XML to java.util.Map and vice versa, only even more generic.

I have an XML document, and I’d like to convert it to a very generic set of key/value pairs (in Java, that is). The basic idea is that we can parse pretty much every XML document and pass it on directly to a JSP file, which can read the values and display them.

Say one has an XML structure as follows:

<root>
  <items>
   <item id="10">Some item here</item>
  </items>
  <things>
   <thing awesome="true">
    <orly-owl hoot="woot" />
   </thing>
  </things>
</root>

The output would be a set of Map objects that both contain values, lists, and other maps. Here’s how, ideally, it’d be read in a (pseudo) JSP file:

<c:forEach var="item" items="${root.items}">
  ${item.id}
  ${item.text}
</c:forEach>
<c:forEach var="things" items="${root.things}">
  Is it awesome? ${thing.awesome}
  orly? ${thing.orly-owl.hoot}
</c:forEach>

Basically, it’d be an xml parser of sorts that has a simple set of rules.

For each XML entity:

Does it have subnodes?

add entry to map with node name as key and List (of maps) as value
Does it have attributes or value?
add entry to map with attribute name as key and attribute value as value

…or something to that degree. I don’t really have the data structure in mind properly yet.

So my question is: Is there a ready-made parser that can do this or something like this?

The ones I’ve found and tried out today all map to a fixed object hierarchy, i.e. you have to create a root object with a List of Item objects with its own properties. This isn’t bad per sé (and it can be auto-generated based on a (to be written / designed) DTD object, but it’s my current assignment to try out both options. Tried the first, it’ll work once those mapping xml files make sense to me and error messages start telling me what I’m doing wrong, but haven’t been able to figure out how to do the second (read: write a recursive xml parser (dom or sax) that recurses recursively).

Coherency may be absent in this question, it’s five ‘o clock.


Edit, after thinking it through some more. It will work (that is, sending Objects to JSP that can contain values, Maps and Lists), however it’ll be terribly problematic while parsing, for example in the next example:

<root thing="thine mother">
  <thing mabob="yus" />
  <thing mabob="nay" />
  <items>
    <item id=1" />
  </items>
</root>

In this particular instance, there’s two same-named thing-elements under the root. Same-named elements should go into a List. However, at the same level there’s an items element, which is a singular element which should go in as a map item. Add to that there’s a third named ‘element’ in the root element, and the whole thing’s buggered.

Without analyzing the structure beforehand (and setting a flag like ‘there’s both same-named and unique-named elements under this particular element’), you cannot assume this. And the last thing I want to do is to force the XML to be according to a particular structure.

My colleague actually suggested running the XML through an XSL so that it’d be ‘flatter’ (more like database rows), or having the xml output have a maximum depth of one. Not an option, really.

Anyways. Thanks for the suggestions all, it seems this isn’t a very plausible solution to the problem – at least not without screwing up basic rules and conventions of XML and Common Sense.

On to the next ideas – having JSP render a Document directly using the XML JSTL library.

  • 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-16T20:04:27+00:00Added an answer on May 16, 2026 at 8:04 pm

    It seems like the JSTL XML bindings will do exactly what you want.

    And the reason that you’re unlikely to find anything that exactly meets your requirements using lists and maps is because XML does not neatly translate into lists and maps (mostly because of the question “how do you treat attributes differently than content?”).

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

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would advise against using the backspace key, since that… May 17, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer (Note: I'll assume that by "decode and dispatch" you mean… May 17, 2026 at 9:02 am
  • Editorial Team
    Editorial Team added an answer Non static properties (alias fields, alias member variables) have their… May 17, 2026 at 9:01 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Although somewhat related to this question , I have what I think is a
I asked a somewhat related question but I want it to make it more
This is somewhat asp.net MVC related only for example purposes but I was hoping
Somewhat related to my question about integers instead of decimals; my vendor provides a
[This question is somewhat related to this question , but the answers are not...]
I realize there is a somewhat related thread on this here: Loading assemblies and
I have somewhat interesting development situation. The client and deployment server are inside a
Somewhat related to this question , but in the absence of any answer about
This question is somewhat related to What’s the simplest way to make a HTTP
This is somewhat related to a similar post , but that post was Visual

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.