Re: javascript and XML help




Martin Honnen wrote:
rbann11@xxxxxxxxxxx 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</strong> is 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</strong> is
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/

Thanks for replying.
Actually, I misunderstood DOM. It does what I want it to.

Keep up the good work,

Roger

.



Relevant Pages

  • Re: javascript and XML help
    ... Some Text and html tags ... That is not well-formed XML so any XML parser will give a parse error. ... 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. ...
    (comp.lang.javascript)
  • Re: HTML dom
    ... REXML can be awkward if you're used to using the DOM. ... XML libs. ... his problem is that he used an XML tool to process HTML. ... The libxml2 c library has contained a correcting HTML processor since it's ...
    (comp.lang.ruby)
  • Re: XML CDATA special characters
    ... I didn't mention SAX, is that the standard PHP parser I'm using now? ... I'll just dive into DOM now and see where this will all end up. ... basic XML only has 5 pre-defined default entities. ... If you try and use HTML ...
    (comp.lang.php)
  • Re: extract inner xml...
    ... I cannot find that functionality in any xml parser in java... ... I was able to do it in DOM by serializing Node - but is stupid solution.... ...
    (comp.text.xml)
  • Re: HTML dom
    ... REXML can be awkward if you're used to using the DOM. ... REXML provides an XML DOM in similar ways as other XML libs. ... his problem is that he used an XML tool to process HTML. ...
    (comp.lang.ruby)