This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes DOM out put not inserting indents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "DOM out put not inserting indents" Watch "DOM out put not inserting indents" New topic
Author

DOM out put not inserting indents

Charles Burton
Ranch Hand

Joined: Jan 31, 2011
Posts: 39

So, first off my code is hand jammed since my dev box is airgapped from the internet. I need to code to the java 1.4 standard(I know I know, it'll be updated someday). So the problem that I'm having is this. I wrote a sample xml file to use as a config. It is as follows.


So the problem that I'm having is when I try to add another error it's not indented properly and it looks like this:


Here is the code that I'm using to update it, most of the other code is omitted, but this part is the action performed for the update button. I'll include the parts in here for how I'm loading the xml document, but that is actually an object that lives elsewhere.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Why do you care that it is not indented the way you expect? Indenting is for human readability

Well written XML parsing code is not going to care how many spaces or line feeds separate element tags.

Bill
Charles Burton
Ranch Hand

Joined: Jan 31, 2011
Posts: 39

Thanks for that helpful reply. I know that the parser doesn't care, but I need it to be human readable. There are situations where this file may need to be hand edited.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41177
    
  45
I don't think JAXP can do this. You may have to resort to parser-specific classes. Not sure if Crimson or Xerces was the parser shipped with Java 1.4.


Ping & DNS - my free Android networking tools app
Charles Burton
Ranch Hand

Joined: Jan 31, 2011
Posts: 39

I think it was Xerces, I'll look into that. Thank you.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
Add the ident-amount to output property of the transformer see if it resolves to what you need.

Charles Burton
Ranch Hand

Joined: Jan 31, 2011
Posts: 39

That produced something even stranger.

g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
[0] Hi. I agree and independently confirm the observation that the passing in DOMSource from edited dom will preserve the "ignorable" whitespace that causes the problem of misalignment. (True, for human-readability). One of the source of obstacle is that the factory method of setIgnoringElementContentWhitespace is only effective when the document is to be validated against a dtd or xsd or others. (There seems to have a unfortunate history of bugs in 1.5 seemingly doing a job but conceptually defective. But, brief...) That stops one from using that facility to re-align the indents. So my above suggestion would not do any good.

[1] In the making of output stream, you can supply, instead of using the build-in identity transformation, a constant & fixed xsl document to do the re-alignment. Let's call it indenter.xsl. It uses xalan extension, though.

[2] With that in the working directory (or relocate it, as long as it is properly pointed to), just modify the line setting up the transformer.

[2.1] After that change, it will do the job.
Charles Burton
Ranch Hand

Joined: Jan 31, 2011
Posts: 39

Excellent, thank you.
 
jQuery in Action, 2nd edition
 
subject: DOM out put not inserting indents
 
Similar Threads
XML Schema catalogs
org.xml.sax.SAXParseException
Getting the arraylist through session
DTD Validation problem via Sax
Page section does not update after call of a4j:support in IE 9