[libxml-devel] << operator

Charlie Savage cfis at savagexi.com
Thu Aug 21 16:01:01 EDT 2008


> So:
> 
> node1 = XML::Node.new('foo')
> node1 << 'bar'
> 
> would produce '<foo>bar</foo>' and not '<foo/>bar'.  However:
> 
> node2 = XML::Node.new('bar')
> node1 << node2
> 
> should produce '<foo><bar/></foo>'.
> 
> If the argument to << is a string, append to the xmlNode->content via 
> xmlNodeAddContent(3).  If, however, the argument is an XML::Node, then 
> use xmlAddChild(3) to add an xmlNode->child node.
> 
> 
> + and << should behave differently:
> 
> 'node1 + node2' should produce '<foo/><bar/>'

Yes, that is how it currently works.  Note if you do this:

node1 = XML::Node.new('foo')
node1 << '<bar/>'

You get this:

<foo>&lt;bar/&gt;</foo>

Which seems fine to me.

However, that doesn't really help with this issue:

node = XML::Node.new('foo') << XML::Node.new('bar') << XML::Node.new('baz')

If << returns self, then you get:

'<foo><bar/><baz/></foo>' where node points to foo

If << returns the appended child, then:

'<foo><bar><baz/></bar></foo>' where node points to baz.  Its the 
pointing to baz bit I don't like.

Charlie
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://rubyforge.org/pipermail/libxml-devel/attachments/20080821/4bd35105/attachment.bin>


More information about the libxml-devel mailing list