[libxml-devel] << operator

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


> 
> XML::Node.new('foo') << XML::Node.new('bar') << XML::Node.new('baz')
> 
> Should produce:
> 
> <foo><bar><baz/></bar></foo>
> 
> XML::Node<<(arg) should return the argument being appended *ONLY IF* the 
> argument is an XML::Node, else it should return the xmlNode that had its 
> content modified (e.g. XML::Attributes and Strings).
> 
> That should solve this problem.

So in this case the first << returns the 'bar' node and the second << 
returns the baz node.

Thus:

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

node is baz.  Which is annoying, because most of the time I imagine you 
want foo (at least I want foo).  Thus, returning the appended argument 
is great, until the very end, where you want the original node...

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/1b96d020/attachment.bin>


More information about the libxml-devel mailing list