[XOM-interest] Writing to XML through XOM APIs

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Jan 23 09:54:49 EST 2004


At 3:45 AM -0800 1/23/04, Ravi Nathwani wrote:

>  The nu.xom APIs for the ëElementí class does have a
>getValue() method, but it does not have a setValue()
>method.


That's because the value does not have a unique 
representation in XML. In other words, any given 
child element has exactly one value, but there 
are many different child elements with that one 
value. For instance, consider the value "Hello 
Ravi". This could be

<child>Hello Ravi</child>
<child>Hello <name>Ravi</name></child>
<child><word>Hello</word> <word>Ravi</word></child>
<child><message><word>Hello</word> <word>Ravi</word></message></child>

Therefore you have to be more explicit about what 
you want to put in the element rather than just 
providing the value. The value is a computed 
property, not a fundamental one.

If you're starting with an empty element and you 
only want to put text in it, you just need to say 
child.appendChild("Hello Ravi"). If the element 
is not empty you may need to remove some content 
first.

-- 

   Elliotte Rusty Harold
   elharo at metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA



More information about the XOM-interest mailing list