By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,693 Members | 1,822 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,693 IT Pros & Developers. It's quick & easy.

javascript and XML help

P: n/a
Hi,

I have a script that contains an XML string that will define how the
page will be displayed.
The XML string contains custom tags, with attributes and html tags.
I will be replacing the custom tags with other html code.

My question is what is the best way to parse the XML string and can it
be done with DOM.
What is bothering me the most is the text before and after the custom
tags.

There is an example of what the XML string will look like:

<root>
Some Text and html tags
<block a="1 "b="2">
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>
Any code or ideas will be helpful.
Thanks in advance
Roger

Jul 25 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a


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/
Jul 25 '06 #2

P: n/a

Martin Honnen wrote:
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/
Thanks for replying.
Actually, I misunderstood DOM. It does what I want it to.

Keep up the good work,

Roger

Jul 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.