Ticket #91 (closed defect: fixed)
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
Note: See
TracTickets for help on using
tickets.
