473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to parse xml from javascript string?

Ok, I've seen many examples of javascript
parsing an XML document retrieved from a file
indicated by a URL.

The problem is I need to parse (usually small)
xml *strings* embedded in the javascript program
or generated locally, and I can't find any way
to do this exposed (even though some internal
part of the engine clearly is capable of doing it).
Am I missing something?

I'm aquainted with Xparse, but it seems to do
strange things with invalid XML
(rather than giving up with an error) and also may
have licensing issues for my purposes. I've seen
references to other parsers implemented in
javascript. Is there a good one with a BSD style
license? Other options?

Please inform! thanks! -- Aaron Watters

===
there ain't no sanity clause!

Dec 3 '05 #1
3 20622


aa***************@yahoo.com wrote:

The problem is I need to parse (usually small)
xml *strings* embedded in the javascript program
or generated locally, and I can't find any way
to do this exposed (even though some internal
part of the engine clearly is capable of doing it).


The JavaScript engine is capable of parsing XML? Well, yes, the
Spidermonkey engine in Firefox 1.5 can do that but that does not help
currently on the web.
Usually you need a host object for that, Mozilla exposes DOMParser e.g.
var domParser = new DOMParser();
var xmlDocument = domParser.parseFromString(
stringWithXMLMarkupHere,
'application/xml'
);
Opera 8 also supports DOMParser and has some minimal support for W3C DOM
Level 3 Load and Save too.
I think Safari 2 or at least the latest 2.something release also
supports DOMParser.
With IE/Win for XML you need to use MSXML anyway and there DOMDocument
exposes a method named loadXML to parse a string and create an XML DOM
document.

For older Safari (and probably Konqueror too) people have managed to
parse XML strings by passing the XML markup in a data URL to
XMLHttpRequest, see <http://web-graphics.com/mtarchive/001606.php>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 4 '05 #2
Thanks very much!

Why is it that my 4 recent large books on javascript don't
have this kind of information? Where is an authoritative
reference (online or otherwise) where I can find this kind
of info? Thanks again!

-- Aaron Watters
===
He's a humble man with lots to be humble about.
-- Churchill

Dec 6 '05 #3
aa***************@yahoo.com wrote:
Why is it that my 4 recent large books on javascript don't
have this kind of information?
Either bad books, or books describing only the language.
DOM parsers are not part of that, but part of the AOM/DOM.
Where is an authoritative reference (online or otherwise)
where I can find this kind of info?
Which kind of info? <URL:http://jibbering.com/faq/faq_notes/pots1.html>.
Usually you need a host object for that, Mozilla exposes DOMParser e.g.
[...]
<URL:http://xulplanet.com/references/objref/>
Opera 8 also supports DOMParser and has some minimal support for W3C DOM
Level 3 Load and Save too.
<URL:http://www.opera.com/docs/specs/>
<URL:http://www.w3.org/TR/DOM-Level-3-LS/>
I think Safari 2 or at least the latest 2.something release also
supports DOMParser.


<URL:http://www.apple.com/macosx/features/safari/>
<URL:http://developer.kde.org/documentation/library/>
With IE/Win for XML you need to use MSXML anyway and there DOMDocument
exposes a method named loadXML to parse a string and create an XML DOM
document.


<URL:http://msdn.microsoft.com/XML/BuildingXML/default.aspx>
Google is your friend. [psf 6.1]
PointedEars
Dec 6 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Watsh | last post by:
Hi All, I have been trying to parse an XML string using the StringReader and InputSource interface but the document returned to me is always null. Please find the code below which i have been...
3
by: Dennis M. Marks | last post by:
I am looking for a javascript function that will parse a query string. Parameters are passed in the url: url?a=3&c=5&etc An array is returned that uses the variable name as the index. array=3...
3
by: Daniel | last post by:
I admit that I am a novice when it comes to the HTML DOM and JavaScript. Basically, here is what I want to do: 1. Import some HTML from a remote web site 2. Parse the HTML to locate a specific...
1
by: Mochuelo | last post by:
Hi I have a string with the following contents: "<TR align=right ID=G><TD align=left><A HREF="/comun/fichaemp/fichavalor.asp?isin=ES0111845014"><IMG SRC="/images/arr-up9.gif" BORDER=0>...
1
by: Stephane | last post by:
Hi, I have a html file file that I want to parse with ASP.NET to retreive the value of a custom tag. Let's say that the average html file is about 30 ko. Once the html file is loaded and...
6
by: Ian Davies | last post by:
Hello I have found the following script php/java for dynamic menu lists. Where a selection from the first updates (filters items in) the other. I have modified it for my tables. However I am...
2
by: PJ6 | last post by:
I can probably code this up manually myself but I'd prefer to use a built-in method that I'm sure exists... I have a message box client-side control (thanks, Steve Orr) that uses the JavaScript...
10
by: Martin Eyles | last post by:
Hi, I am getting a string passed back from a web form in the format name1:variable1;name2:variable2... I would like to split this up into several variable, such that the variable names are...
3
by: CribbsStyle | last post by:
Ok, I've got to where I can download the source code of a webpage, the problem is how do I parse this source code? I would to be able to pull the below all out of the source... Full Names The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.