Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOM out put not inserting indents

 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it was Xerces, I'll look into that. Thank you.
 
g tsuji
Ranch Hand
Posts: 669
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the ident-amount to output property of the transformer see if it resolves to what you need.

 
Charles Burton
Ranch Hand
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That produced something even stranger.

 
g tsuji
Ranch Hand
Posts: 669
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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
Posts: 39
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent, thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic