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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:06:36+00:00 2026-05-24T10:06:36+00:00

I find myself writing the same verbose DOM manipulation code again and again: Element

  • 0

I find myself writing the same verbose DOM manipulation code again and again:

Element e1 = document.createElement("some-name");
e1.setAttribute("attr1", "val1");
e2.setAttribute("attr2", "val2");
document.appendChild(e1);

Element e2 = document.createElement("some-other-name");
e.appendChild(e2);

// Etc, the same for attributes and finding the nodes again:
Element e3 = (Element) document.getElementsByTagName("some-other-name").item(0);

Now, I don’t want to switch architecture all together, i.e. I don’t want to use JDOM, JAXB, or anything else. Just Java’s org.w3c.dom. The reasons for this are

  1. It’s about an old and big legacy system
  2. The XML is used in many places and XSLT transformed several times to get XML, HTML, PDF output
  3. I’m just looking for convenience, not a big change.

I’m just wondering if there is a nice wrapper library (e.g. with apache commons or google) that allows me to do things like this with a fluent style similar to jRTF:

// create a wrapper around my DOM document and manipulate it:
// like in jRTF, this code would make use of static imports
dom(document).add(
  element("some-name")
    .attr("attr1", "val1")
    .attr("attr2", "val2")
    .add(element("some-other-name")),
  element("more-elements")
);

and then

Element e3 = dom(document).findOne("some-other-name");

The important requirement I have here is that I explicitly want to operate on a org.w3c.dom.Document that

  1. already exists
  2. is pretty big
  3. needs quite a bit of manipulation

So transforming the org.w3c.dom.Document into JDOM, dom4j, etc seems like a bad idea. Wrapping it with adapters is what I’d prefer.

If it doesn’t exist, I might roll my own, as this jRTF syntax looks really nice! And for XML, it seems quite easy to implement, as there are only few node types. This could become as powerful as jquery from the fluent API perspective!

  • 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-24T10:06:38+00:00Added an answer on May 24, 2026 at 10:06 am

    I found some tools that roughly do what I asked for in my question:

    • http://code.google.com/p/xmltool/
    • http://jsoup.org/

    However, in the mean time, I am more inclinded to roll my own. I’m really a big fan of jquery, and I think jquery can be mapped to a Java fluent API:

    http://www.jooq.org/products/jOOX

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

Sidebar

Related Questions

I constantly find myself writing similar code like the example below: if (object[Object Name]
I find myself writing code like this when I want to repeat some execution
Recently, I find myself writing code like this: for name in dir( object ):
I find myself writing code that looks something like this: $(document).ready(function(){ updateStuff(); $('select').change(function(){ updateStuff();
I ofetn find myself writing the same code in jquery for ajax stuff. Still
I find myself writing code that looks like this a lot: set<int> affected_items; while
I find myself writing code such as: foreach($array as $key => $value) { switch($key)
I frequently find myself writing code like this: List<int> list = new List<int> {
I always find myself writing code like this: my $var = $result[0]; my $var_changed
I find myself writing SQL code (queries or stored procs) to solve problems that

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.