Re: [xml] entity conversion

On Wed, Aug 19, 2009 at 10:07 AM, Andrew Hume<andrew research att com> wrote:
<Company>  AT&amp;T </Company>
i parse this using
doc = LibXML::XML::Document.file('foo.xml')
if node points to this element, then
node.content == 'AT&T'
all well and good. if i want to now create a new document,
then i do
newnode ='Company')
newnode.content = node.content
and this assignment has the error 'unterminated entity reference'
(which could be fair given that it is literally an unterminated entity
the question is should assignment of content automatically do teh conversion
or should teh user be responsible?

IMO, this is a bug in the LibXML-Ruby API.  It seems reasonable to be
able to pull the content from one node and assign it to another.

You could try other ruby bindings to libxml2 like Nokogiri*:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'nokogiri'
=> true
irb(main):003:0> doc =
=> <?xml version="1.0"?>

irb(main):004:0> node ='foo', doc)
=> <foo/>
irb(main):005:0> node.content = 'foo&bar'
=> "foo&bar"
irb(main):006:0> node.to_xml
=> "<foo>foo&amp;bar</foo>"

* I wrote these bindings so I am biased.

Aaron Patterson

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]