473,804 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20644


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.parse FromString(
stringWithXMLMa rkupHere,
'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.o rg/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
6298
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 experimenting with: import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import org.xml.sax.InputSource; import org.w3c.dom.Document;
3
4923
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 array=5 etc. -- Dennis M. Marks http://www.dcs-chico.com/~denmarks/
3
1751
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 tag based on font weight and font size 3. Check the text in that tag to see if it matches a specified string Does anyone have any ideas?
1
1201
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> ABERTIS SE.A</A></TD><TD>19,96</TD><TD ID=V>0,15</TD><TD>19,96</TD><TD>19,83</TD><TD>1.060.525</TD><TD>21.115,00</TD><TD align=center>27/06/2005</TD><TD align=center>17:35</TD></TR>"
1
2369
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 converted into a single string, I'm using for now is two string.indexOf to find the begin and the end of the desired tag and then a string.substring to extract the data. I'm not using regular expressions since I know exactly what are the tags to find....
6
2199
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 getting an error Parse error: parse error, unexpected T_VAR in e:\domains\i\iddsoftware.co.uk\user\htdocs\QuestionDB\Questions.php on line 42
2
1728
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 alert() method to pass text to a user in a dialogue box. Often I have messages containing text that JavaScript doesn't like, like single quote characters. Does ASP.NET have a method to parse text for JavaScript? Server.HTMLEncode doesn't seem to do...
10
1373
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 name1, name2 etc. (I actually know what these names are) and the values of the variables are variable1, variable2 etc. I tried using split to split the string into an array at the semicolons, and
3
1157
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 number in "javascript:profile(NUMBER)" Now as you can from the source below, Each Full Name Goes with a Number, how can I arrange this, so after parsing I know which number
0
9594
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
10343
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...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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
7634
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
6862
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
5530
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...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.