Ticket #91 (closed defect: fixed)

Opened 2 years ago

Last modified 16 months ago

Weird outputting of a already parsed XML file after changes.

Reported by: Kamu Owned by: ser
Priority: normal Milestone: 3.1.8
Component: DOM Version: 3.1.5
Severity: normal Keywords:
Cc: Ruby version: 1.8.2
Operating system: Linux

Description

When I parse an XML file and then write it out, I get weird output.

e.g. My original XML file:

<root>
  <bah something='1' somethingelse='bah'>
    <something>great</something>
  </bah>
</root>

When I simply add an element to the file's root element it will mess up the indentation:

<root>
  <bah something='1' somethingelse='bah'>
    <something>great</something>
  </bah>
  <bah/>
<bah/>
</root>

My code is very simple:

irb(main):018:0> doc = Document.new(File.new("somexml.xml"))
irb(main):019:0> doc.root.add_element "bah"
irb(main):020:0> f = File.new("somexml.xml", "w")
irb(main):021:0> doc.write(f, 0)
irb(main):022:0> f.close

Also, if there is an XMLDecl, it will add new lines after it. Sometimes there will be trailing newlines at the end of the file too.

Change History

Changed 2 years ago by Kamu

Sorry, in my 2nd XML paste I accidently added another <bah/> which can be seen above the incorrectly indented <bah/> element.

Changed 2 years ago by Kamu

Ok, if you add :ignore_whitespace_nodes => :all to when the document is opened, all these problems go away. But I still think that is weird behavior, especially the new lines after XMLDecls and at the end of the file.

Sorry for wasting your time.

Changed 16 months ago by ser

  • milestone set to 3.1.8

Changed 16 months ago by ser

  • status changed from new to closed
  • resolution set to fixed

This is fixed in the 3.1.7 release, when all of the XML output code was refactored. I've added a unit test in changeset:1269. This code exposed a bug in the refactored pretty printer, and the fix for that is in changeset:1270.

Note: See TracTickets for help on using tickets.