Dylan Parry wrote:
I have an XML node
What kind of node is that exactly, an element node, a text node, a
fragment node?
"This is <em>some text</em>"
How can I get the
exact string above returned?
It depends on the XML object model you use, with MSXML that you use in
ASP or in IE you can serialize each node using its property named 'xml' so
node.xml
gives you the serialized XML of the node.
However in the above case you have
This is <em>some text</em>
contained in some other node (probably an element node) and you need to
be aware that if you use
node.xml
on the container node that you get the start tag, attributes, and end
tag of the container node serialized as well.
Thus if you only want to serialize the child nodes then you need to loop
through and concatenate the xml of each child node (a text node, an
element node, a text node in that example).
With the W3C DOM to serialize a DOM node you would need DOM Level 3 Load
and Save, currently inside browsers only Opera 8 and 9 have a minimal
implementation of that.
However Mozilla introduced the proprietary XMLSerializer and other
browsers have implemented that too (Opera, recent Safari, Konqueror) so
there to serialize a node you do e.g.
var xmlSerializer = new XMLSerializer() ;
then to serialize a node to a string
var s = xmlSerializer.s erializeToStrin g(node);
Again for your case above you would need to loop over the child nodes of
the container node and serialize each child node.
--
Martin Honnen
http://JavaScript.FAQTs.com/