rb*****@hotmail .com wrote:
My question is what is the best way to parse the XML string and can it
be done with DOM.
<root>
Some Text and html tags
<block a="1 "b="2">
^^^^^
That is not well-formed XML so any XML parser will give a parse error.
Some Text and html tags
<block>
Some Text and html tags
<tag1</tag1>
<tag2</tag2>
<tag3</tag3>
<tag3</tag4>
</block>
<block a="4">
Some Text and html tags
<tag1</tag1>
<tag2</tag2>
</block>
</block>
Some Text and html tags
</root>
If you want to parse XML from a string then look into
<http://www.faqts.com/knowledge_base/view.phtml/aid/15302/fid/616>
You need to be aware however that such an XML parsing will give you XML
DOM nodes, it does not help that some of them might have the same tag
name as HTML elements e.g.
<root>
<p><strong>Kibo </strongis God.<p>
</root>
will parse root as well as p or strong into an XML DOM element node. And
those XML DOM element nodes do not become HTML DOM element nodes later
if you try to insert them into an HTML DOM document to have them rendered.
With browsers like Mozilla or Opera which have a common DOM
implementation beneath their HTML and XML parsers you could get XHTML
DOM nodes by using the proper XHTML namespace e.g.
<root>
<p xmlns="http://www.w3.org/1999/xhtml"><strong> Kibo</strongis
God.<p>
</root>
that way the XML parser will create XHTML element nodes for those
elements in the XHTML namespace and these nodes can then be imported and
rendered in a HTML DOM document.
But IE has separate HTML and XML parsers and DOM implementations so its
XML parser will not do anything special with elements in the XHTML
namespace.
--
Martin Honnen
http://JavaScript.FAQTs.com/