Javascript XML parsing

Jason Harlan's icon

Hi - I'm new to the list and a month into Max.

I tried instantiating an XML parser in Javascript, in Max/MSP, and couldn't
find one. This seems unfortunate. Am I missing something? Is there one
included? ( I tried DOMParser and searched for sample code )

I finally used a parser built out of regular expressions - which works I
guess. Though, it's not super clean.

I tried using [ detox ] and the tap parser, though they didn't load the file
contents into a DOM tree like structure I'm familiar with.

Thanks for any thoughts.

Jason Harlan
Visiting Researcher - USC Interactive Media Division
http://interactive.usc.edu

Jennek Geels's icon

The Document Object Model and JavaScript are separate entities.
They only happen to meet in your web browser.

You could acces the DOM without JavaScript, for example with XSLT.
And you can do things in JavaScript without the DOM.
Also known as Core JavaScript, which is what Max has adopted.
HtH
-jennek

Jason Harlan's icon

That's clear - thanks.

batchku's icon

it was jason's question, so i'm glad it's clear to him and he got it
but jennek, would you please give me a little more detail on how
you'd do xml parsing just with javacript (or Core Javascript)?

thanks,
a

Joshua Kit Clayton's icon

On Nov 8, 2005, at 12:58 PM, Jason Harlan wrote:

> I tried instantiating an XML parser in Javascript, in Max/MSP, and
> couldn't find one. This seems unfortunate. Am I missing
> something? Is there one included? ( I tried DOMParser and
> searched for sample code )

> I finally used a parser built out of regular expressions - which
> works I guess. Though, it's not super clean.

The following has both DOM and SAX style parsers written in Core JS.
You would just use the MaxMSP file object to read in the file to a
string which could be passed to these functions.

Note that you can add classes and functions to be used by other
scripts by placing the js file in the jsextensions folder, as is
discussed in the following archive post, and demonstrated by the
Jitter utility jsextensions installed with Jitter:

Let us know if you encounter any problems.

-Joshua

Jason Harlan's icon

Ali,

this is what i used:

and here's another - an elegant regular expression parse:

though it lacks higher level method calls that the gazingus one has.

Jason

Jennek Geels's icon

Ali,
I'd look for a public domain library capable of parsing XML into a DOM
(and serializing the DOM back to XML), that could be called from the Max
Core JavaScript implementation.

And luckily enought I do not have to search the web for this anymore,
as Joshua has already posted the URL where such a library can be found.

On 8 Nov 2005, at 22:49, Joshua Kit Clayton wrote:
> http://xmljs.sourceforge.net/

This particular library is written in JavaScript, so it is easy to
understand
how you would use its classes in your javavascripts. As Joshua recalled,
put it in the jsextensions folder

The DOM is a pretty large animal and a full XPath implementation is
absolutely
nontrivial, so we are lucky that other people have created this
library and share it with us.
-jennek

mzed's icon
wallace winfrey's icon

Hi Javascript-Dev

On Monday, this message was posted to the MaxMSP 2005 Mailing List archives, which automatically put it in the queue, as the mailing list archives are read-only, and no longer accepting entries. Sometimes, people will reply to an old thread and it will get updated in the list archives, and I'll move it out to the main MaxMSP list.

In this case though, a post was made through the forum (note to users: please don't reply to old threads in the list archives!), but it also happened to be a thread which more appropriately goes into the Javascript forum. Therefore, I've moved this old max-msp list thread to this forum.

List subscribers, I would encourage you to visit the thread and read over mzed's posting, and see if you can offer any help. Here's a direct link to this thread:

Sorry for the length of this message, it's just a somewhat difficult situation to explain.

cheers

w

SoftXML's icon

You can try SoftXPath ---> http://www.softxml.com/softxpathdemo.htm
This is a small cross browser JavaScript library written for web developers who deals with XML parsing/querying on client side. You will be able to query complex XML documents using powerful Xpath expressions. Now you can focus on building effective Xpath expressions instead of wasting time on browser compatibility issues.

keepsound's icon
Max Patch
Copy patch and select New From Clipboard in Max.