Hey Emmett, dunno if you saw this response (below), but here's the relevant bit:
# just make sure you format it on output
> format = true
> # => true
> doc.save('output.xml', format)
> # => 352
> <?xml version="1.0"?>
> <root_node>
> <elem1 attr1="val1" attr2="val2"></elem1>
> <elem2 attr1="val1" attr2="val2"></elem2>
> <elem3></elem3>
> <foo>
> <bar1></bar1>
> <bar2></bar2>
via Document#save
http://libxml.rubyforge.org/doc/classes/XML/Document.html#M000287
HTH,
Keith
Keith Fahlgren wrote:
> Emmett Shear wrote:
>> I can remove the byte order markers myself pretty easily; is there any
>> way to force libxml to output empty tags in <foo></foo> form?
>
> Hi Emmett,
>
> I think what you want to manipulate is xmlSaveNoEmptyTags[1] sadly, I don't
> know
> enough C and can't find anything similar to try to copy.
>
> All that said, Trans' hack is a good one:
>
> $ irb --prompt xmp libxml2.irb && cat output.xml
> require 'rubygems' # if installed via Gems
> # => true
> require 'xml/libxml'
> # => true
>
> doc = XML::Document.new()
> # => <?xml version="1.0"?>
>
> doc.root = XML::Node.new('root_node')
> # => <root_node/>
> root = doc.root
> # => <root_node/>
>
> root << elem1 = XML::Node.new('elem1', "")
> # => <elem1></elem1>
> elem1['attr1'] = 'val1'
> # => "val1"
> elem1['attr2'] = 'val2'
> # => "val2"
>
> root << elem2 = XML::Node.new('elem2', "")
> # => <elem2></elem2>
> elem2['attr1'] = 'val1'
> # => "val1"
> elem2['attr2'] = 'val2'
> # => "val2"
>
> root << elem3 = XML::Node.new('elem3', "")
> # => <elem3></elem3>
>
> # Namespace hack to reduce the numer of times XML:: is typed
> include XML
> # => Object
> root << elem7 = Node.new('foo')
> # => <foo/>
> 1.upto(10) {|i| elem7 << n = Node.new("bar#{i}", "") }
> # => 1
>
> format = true
> # => true
> doc.save('output.xml', format)
> # => 352
> <?xml version="1.0"?>
> <root_node>
> <elem1 attr1="val1" attr2="val2"></elem1>
> <elem2 attr1="val1" attr2="val2"></elem2>
> <elem3></elem3>
> <foo>
> <bar1></bar1>
> <bar2></bar2>
> <bar3></bar3>
> <bar4></bar4>
> <bar5></bar5>
> <bar6></bar6>
> <bar7></bar7>
> <bar8></bar8>
> <bar9></bar9>
> <bar10></bar10>
> </foo>
> </root_node>
>
>
> HTH,
> Keith
> 1. http://xmlsoft.org/html/libxml-globals.html#xmlSaveNoEmptyTags
> _______________________________________________
> libxml-devel mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/libxml-devel
>
_______________________________________________
libxml-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/libxml-devel