[libxml-devel] << operator

Sean Chittenden sean at chittenden.org
Sun Aug 24 12:21:35 EDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>> It is easy when << returns self:
>>
>> A << (B << C) \
>>  << (D << E)
>>
>> This makes A with two children B and C each with a
>> If you want a path (tree without branches),
>> you can still do
>>
>> A << (B << (C << D)))
>
> Doh! Of course.
>
> It has to return self.


I think the most common case is going to be something like this:

<frag>
   <some_block>
     <a/>
     <b/>
     <c/>
   </some_block>
   <other_block>
     <d/>
     <e/>
   </other_block>
</frag>


And the programatic construction of it will look like:

def n(a)
   XML::Node.new(a)
end

some_block = n('some_block') << (n('a') + n('b') + n('c'))
other_block = n('other_block') << (n('d') + n('e'))
root = n << some_block + other_block



... And I think the thing that needs to happen is this needs to be  
documented somewhere because XML construction is one of those things  
that people tend to like to want to do with XML libraries vs. nested  
function calls w/ string concatenation.  -sc


- --
Sean Chittenden
sean at chittenden.org



-----BEGIN PGP SIGNATURE-----

iEYEARECAAYFAkixio8ACgkQTrydwWwuXha9vQCeIYz+gNj6VyPNHEIkNFnhzbUW
hfQAn0DfHUfiCiDcbXrqOMz+ZJu6FdYz
=V3ic
-----END PGP SIGNATURE-----


More information about the libxml-devel mailing list