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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:01:47+00:00 2026-06-09T23:01:47+00:00

i have some already generated xmls and the application causing problems now needs to

  • 0

i have some already generated xmls and the application causing problems now needs to add elements to it which need to be at a specific position to be valid with to the applied schemata…

now there are two problems the first one is that i have to hardcode the positions which is not that nice but “ok”.
But the much bigger one is jdom… I printed the content list and it looks like:

element1
text
element2
element4
text
element5

while the textnodes are just whitespaces and every element i add makes it even more unpredictable how many textnodes there are (because sometimes there are added some sometimes not) which are just counted as it were elements but i want to ignore them because when i add element3 at index 2 its not between element2 and element4 it comes after this annoying textnode.

Any suggestions? The best solution imho would be something that automatically puts it where it has to be according to the schema but i think thats not possible?

Thanks for advice 🙂

  • 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-09T23:01:48+00:00Added an answer on June 9, 2026 at 11:01 pm

    The JDOM Model of the XML is very literal… it has to be. On the other hand, JDOM offers ways to filter and process the XML in a way that should make your task easier.

    In your case, you want to add Element content to the document, and all the text content is whitespace….. so, just ignore all the text content, and worry about the Element content only.

    For example, if you want to insert a new element nemt before the 3rd Element, you can:

    rootemt.getChildren().add(3, new Element("nemt"));
    

    The elements are now sorted out…. what about the text…

    A really simple solution is to just pretty-print the output:

    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
    xout.output(System.out, mydoc);
    

    That way all the whitespace will be reformatted to make the XML ‘pretty’.

    EDIT – and no, there is no way with JDOM to automatically insert the element in the right place according to the schema….

    Rolf

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

Sidebar

Related Questions

I have an ASP.NET project which has already some custom fields in it's web.config
I have googled some time now trying to find a good sample application that
I have some PDF files generated based on some XSL-FO documents and I now
I have already some applets ready. I tried to run it on android tablet.
I have found already some similar discussion on this, but would like to investigate
I have some scenes set up and already embedded them in the navigation stack
i have a object in javascript and some already defined functions. but how can
i seem to have some trouble installing autopy.h https://github.com/msanders/autopy/#introduction i already tried the installation
I have already read some posts, but no one helped me with my problem.
I have already implemented some AJAX pagination in my Rails app by using the

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.