JS XML Parser documentation

P

Phat G5 (G3)

Has anyone seen a great tutorial on how to use the dom to properly parse an
xml document? I was hoping to find something in depth that might show maybe
via a pictorial how child nodes and node data etc relates to an example xml
document.


Thanks!
 
C

cwdjrxyz

Phat said:
Has anyone seen a great tutorial on how to use the dom to properly parse an
xml document? I was hoping to find something in depth that might show maybe
via a pictorial how child nodes and node data etc relates to an example xml
document.

If you write vour document in W3C xhtml 1.1 (which can be all xml, all
html, or a combination of both) and serve it properly using the mime
type application/xhtml+xml., then it is very easy to parse the document
as xml since the browser automatically does it for you. If you use a
recent Mozilla family browser(Firefox, Mozilla, Netscape) or Opera, the
document is parsed as xml rather than html. The least little xml error
will either prevent the page from displaying at all and/or give an xml
error message rather than a view of the page. Of course IE6 can not
handle true xhtml served with the mentioned mime type, so it does not
allow the page to be viewed. Use of a php include at the very top of
the page can automatically convert the page from xhtml 1.1 to html 4.1
strict for IE6 or older other browsers that can not used the mentioned
mime type for xhtml/xml pages.

Now if you are wanting to build your own parser, that likely will be
much more difficult. I have found no need to do so because of the
things discussed in the first paragraph. Building new browsers and
parts of them such as parsers are chores that very few people are
experienced enough to undertake.
 
M

Martin Honnen

Phat said:
Has anyone seen a great tutorial on how to use the dom to properly parse an
xml document? I was hoping to find something in depth that might show maybe
via a pictorial how child nodes and node data etc relates to an example xml
document.

Well you could use a Mozilla browser (Mozilla suite or Firefox or
Netscape 7) and load your XML document with the DOM inspector, then you
can see what tree the browser builds. It is not a static picture but a
tree structure where you can examine each node and its properties.
 
C

cwdjrxyz

Phat said:
What I mean is :

Something like
http://www.w3schools.com/dom/dom_document.asp

That shows an xml tree and then shows how the dom elements in the link above
relate to each component of the tree.

Go to Google, select advanced search, and require "xml" and "parser" in
the "require all words" box. You will get a huge list of xml parsers
developed by Apache, Sun, etc. These mostly seem to be written in JAVA
or C++. These higher languages likely are much more suited to parsers
and their applications than is Javascript. The list at Google is very
long, so you may find a ready-made parser that you can download that
will do what you wish.
 
P

Phat G5 (G3)

Go to Google, select advanced search, and require "xml" and "parser" in
the "require all words" box. You will get a huge list of xml parsers
developed by Apache, Sun, etc. These mostly seem to be written in JAVA
or C++. These higher languages likely are much more suited to parsers
and their applications than is Javascript. The list at Google is very
long, so you may find a ready-made parser that you can download that
will do what you wish.

I am guessing this is my lack of explaining it correctly. I already have a
nice little function I found on quirksmode that downloads the xml for me
just fine. Problem is parsing the tree via javascript NOT java or c++. I
know that Mozilla has some nice DOM references but they only list the
methods. I did search on google for a while and found a few links that were
close to what I was after but not an exact match.


http://www.captain.at/howto-ajax-xml-javascript.php
The above link gives some good examples but I was hoping to find something
more in depth.



http://www.w3schools.com/dom/dom_document.asp
 
C

cwdjrxyz

Phat said:
I am guessing this is my lack of explaining it correctly. I already have a
nice little function I found on quirksmode that downloads the xml for me
just fine. Problem is parsing the tree via javascript NOT java or c++. I
know that Mozilla has some nice DOM references but they only list the
methods. I did search on google for a while and found a few links that were
close to what I was after but not an exact match.


http://www.captain.at/howto-ajax-xml-javascript.php
The above link gives some good examples but I was hoping to find something
more in depth.



http://www.w3schools.com/dom/dom_document.asp

The examples shown at the w3schools link just above are for IE only,
and use code that does not conform to current official W3C web
standards. For example, a vbscript, not javascript, is used, which is
Microsoftese and not part of official code. When you press the button
in the first example, you get an output that includes a document.write
which is not allowed in the most recent html (xhtml 1.1). You likely
can find information concerning the Microsoftese used somewhere on the
vast Microsoft sites. I have absolutely no interest in using
non-standard Microsoftese, and so far I have been able to avoid it. On
some applications you may be forced to use it to reach IE6 viewers, but
use of it is a last resort in my opinion. Hopefelly this Microsoft
nonsense for the badly outdated IE6 browser will be cured in the IE7
now undergoing testing, but I doubt if the code for IE7 will be
completely cleaned up. Microsoft did nearly no browser development for
years - perhaps they thought it would improve with age, as do some fine
red wines. In the meantime, Mozilla, Opera, and others greatly improved
their browsers. Can Microsoft catch up nearly overnight with their rush
upgrade to IE7?
 
M

Martin Honnen

Phat G5 (G3) wrote:

I am guessing this is my lack of explaining it correctly. I already have a
nice little function I found on quirksmode that downloads the xml for me
just fine. Problem is parsing the tree via javascript NOT java or c++. I
know that Mozilla has some nice DOM references but they only list the
methods.

Mozilla (and Opera for instance) implements the W3C DOM, most of Level 2
Core, that is documented here:
<http://www.w3.org/TR/DOM-Level-2-Core/>
The text explains and defines various interfaces using an interface
definition language (IDL) but there are additional bindings for
ECMAScript, which is the standard for the core of the JavaScript language.

Element objects in JavaScript/ECMAScript will implement the interface
Element specified here
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-745549614>
for instance, and where the IDL says e.g.
readonly attribute DOMString tagName;
the element objects exposed to script will have a (readonly) property named
tagName
of the primitive ECMAScript/JavaScript type string.
Methods in the interface then translate to methods of the object.

The whole DOM specification makes uses of inheritance when specifying
those interfaces so the interface Element inherits from the interface Node
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
which for scripting simply means every element object you have has all
those properties and methods defined by the Node interface too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top