473,978 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript and XML help

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
2 1406


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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
10356
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11413
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11582
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7618
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.