Forums > MaxMSP

Max and XML

August 19, 2011 | 9:55 am

Hi!
Does anyone knows about the ability of Max to interpret xml datas?

Thank you!


August 19, 2011 | 11:39 am

HI,

Have a look at detox (jasch object) or tap.xml.sax (based on the Java SAX parser, part of the tap tools).

You can download the Jasch objects here : http://www.jasch.ch/dl/jasch_objects_0_5.dmg

good luck !


August 19, 2011 | 4:07 pm

Ok, thank you, I’ll have a look on that, which might take me some time ..
: )


August 19, 2011 | 4:33 pm

Well, Max crashed 4 times since I’ve started with Jasch’s detox and stuff. Is it reasonable to keep working with it?? Has anyone some experience with it?


August 19, 2011 | 5:31 pm

Tell us what you are tying to do, sometimes regexp is good enough to extract the content of xml tags.

About detox, there is a nice example on the CNMAT website, the Weather Report.

Here is a slightly modified version :

– Pasted Max Patch, click to expand. –

August 19, 2011 | 11:18 pm

If you know Java at all you can use JDOM. I’ve found this quite useful in parsing XML within Max.

http://www.jdom.org/


August 21, 2011 | 8:36 am

The absolute best XML parser for Max/MSP was created by Ádám Siska and is available from http://www.sadam.hu/?q=node/7. As it warps the RapidXML parser, it is blazingly fast and has been selected after testing many other algorithms. The object is 99% W3C-compliant (in contrast to detox) and very robust.
I a personal communication, Ádám wrote:

I chose the rapidXML library as my back-end after considering 14 different XML parser libraries, and I decided to use rapidXML as that turned out to be the fastest, yet still robust enough solution that has been written using a language supported by the Max SDK (these are C/C++, Java, Obj-C and JavaScript). As a comparison, it is at least 15x faster than the C implementation of Xerces (the authors of rapidXML claim that it is 50x-100x faster, but I searched for more comparisons on the Internet and the worst one I’ve found still claimed rapidXML to be 15x faster) and around 25x faster than the Java implementation, which is the one that most JVMs use as default back-end to the org.w3c.dom package. On the other hand, rapidXML is a library that is being used by thousands of users, including as big companies as HTC. These properties of the library convinced me that whatever solution is used for XML parsing in JMSL, it can’t be as efficient as the rapidXML library is (actually there is no Java XML library that would be among the top-speed XML parsers out there — according to most benchmarks I’ve found, the three best XML parsers are Tango, libXML and rapidXML, however AFAIK Tango is written in the D language, which is not supported by Max, and libXML was simply too big and complicated to use in this project).


August 21, 2011 | 10:50 am

Thanks for your post, I wasn’t aware of this one. I already have the Sadam Lib but I can’t see the rapidXML object ? Could you post it on the list ?


August 21, 2011 | 11:28 am

It’s a recent addition. Have you reloaded his library? If not, contact me at georghajdu@mac.com and I’ll send you a copy. Please let me know what platform you’re on.

Georg§



pid
August 21, 2011 | 5:32 pm

yes, the sadam objects on his website are older (from december 2010). any news on updates would be fantastic.

thanks.


August 23, 2011 | 5:21 pm

I can’t see the rapidXML object either. There is this separate folder rapidxml.1.13 including .hpp files, which I don’t know what to do with.
I would be glad to try this library out!
Thank you all for your answers, which will give me some work ; )


August 24, 2011 | 3:25 pm

Hello everybody,

yes, the [sadam.rapidXML] is going to be included in the next release of my library. I’m still doing some small fixes here and there (documentation, Windows builds etc), but probably it will be available in less than two weeks.

Thank you for your patience,
Ádám


August 26, 2011 | 10:18 am

Looks great! thank you!

http://cycling74.com/toolbox/the-sadam-library/


July 14, 2012 | 9:16 pm

I’m using sadam.rapidXML. Can I serialize XML after I construct it in sadam.rapidXML object? i.e. I need XML as single message.


July 14, 2012 | 11:14 pm

Hi acousmatist,

no, unfortunately there’s no ‘direct’ command that could do that for you. You can, however, save the XML to a file on the disk (I would use a temporal file for that purpose) and pass the file’s name to the part of your program that needs to access the same XML. You can also send a getTree message to sadam.rapidXML and collect the output messages, which you can use later to build the XML again using another instance of sadam.rapidXML. This might be the way to go if you can’t solve the problem with a local temporal file, for instance, because you need to transmit the XML to another machine. If this was your case, you might catch the messages with the sadam.lzo object (since you’re already using my library, it should already be installed) and send the messages compressed through the network. Since getTree gives you all the information about the XML, it should be more-or-less straightforward to rebuild the whole XML based on those messages.

Indeed, this is something that didn’t come to my mind when I created this object, but could be a useful feature. I might extend the external with some easier way to serialize the information contained by it. However, since I’m developing the whole library in my spare time, I can’t say when this could happen.

Hope this helps,
Ádám


July 15, 2012 | 11:04 am

Hi,

it’s me again. I had my bad dreams for not having included this very simple and evident feature in my original release. So, I added it this morning. Attached is the new version (compiled for Mac OS X Intel machines). Now there’s a ‘serialize’ message which will output the full XML as a single message on the rightmost outlet (a separate outlet was added for this functionality on the rightmost side, so it shouldn’t affect old patches using sadam.rapidXML). Documentation, compiled version for other systems (Windows, PPC) and so on will come with the next release of the sadam library.

Hope this helps,
Ádám


July 31, 2012 | 10:08 am

I removed the attachment of my previous comment as the modifications for the [sadam.rapidXML] object are now included in the latest release of my library, see Forum post http://cycling74.com/forums/topic.php?id=41698 .


July 31, 2012 | 12:50 pm

Hi Siska,

as you probably already know the Max SDK includes an API for XML parsing (ext_xmltree.h)
Certainly from a 3rd party developer’s point of view it’s a lot more convenient to use ext_xmltree.h,
since it’s already integrated in the API, but did you ever try to wrap the ext_xmltree.h functions into an external ? Did you ever make any comparison with rapidXML ?
Any comments?

Thanks a lot.

- Luigi


July 31, 2012 | 2:37 pm

Hi Luigi.

Unfortunately, ext_xmltree.h is officially undocumented (see http://cycling74.com/forums/topic.php?id=31221 )… or do you have examples or other info about it?

aa


July 31, 2012 | 3:11 pm

I know it’s undocumented but I figured out how to use it… :)
It’s a pretty simple parser if you ask me, probably based on a DOM implementation which would fit perfectly the Max object oriented paradigm.
But I think when it comes to XML Siska has more experience than I have, so I just wanted to ask his opinion… my curiosity…

Ciao.

- Luigi


July 31, 2012 | 4:44 pm

Hi Castelli,

unfortunately I didn’t make a comparison to the routines included in ext_xmltree. In fact, when I developed this object, I didn’t even know that ext_xmltree exsisted at all, since it was not mentioned anywhere in the SDK docs. On the other hand, in the original commission for this object (by the MaxScore team) overall speed was of key importance, therefore I decided to use from the very first moment a third-party solution that had already been used and tested by thousands of users and reported to be robust and fast. I compared around 15 parsers (among others RapidXML, VTD-XML, IrrXML, TinyXML/TiCPP, NanoXML, ezXML, libXML, ExPat, xmlPull API, FastXML, PugiXML, gSOAP, xmlLite, Xerces etc.) before choosing RapidXML, since at that time every benchmark reported RapidXML to be among the fastest ones and, on the other hand, it was very tiny and easy to include in an external (it consists of only 4 header files, which is nothing compared to the size of, for example, Xerces). Some benchmarks actually reported that the parsing speed of RapidXML is comparable to the time that a call to strlen() takes on the same input stream… Well, to be honest, I didn’t benchmark these tools for myself, but believed what I found on the web. I know, it’s a bad habit, but I just didn’t have the time to build a dozen of parsers and benchmark all of them one-by-one.

I also decided to use a third-party tool because XMLs can be tricky some times, and I wanted to have something that won’t crash with a mal-formatted XML or with XMLs with more sophisticated things, like CDATA elements and so on. Since RapidXML is used by HTC in their phones, witch means that it was probably tested by millions of users, I simply decided to trust it in this sense as well.

Hope this helps,
Ádám


August 1, 2012 | 8:31 am

@ Luigi: would you mind giving me some hints (or code snippets) about how to use the ext_xmltree API?

Thanks!!
aa


August 1, 2012 | 10:18 am

Hi Andrea,

sure, no problem, email me offline at:
superbigio[AT]yahoo[DOT]com

- Luigi


March 16, 2013 | 9:37 pm

Great thanks to Siska Adam! Serialization is very helpfull option.

Does anybody know about problems with adding number as attribute? "setAttribute 1 id NUMBER" works, but "setAttribute 1 id 11" doesn’t. Imho it’s normal in XML to set number as attribute.


March 16, 2013 | 11:44 pm

Hi,

the XML standard itself defines all attributes as strings. If you look carefully at any XML, you will always find that attribute values are enclosed between quotation marks. This is something that I implemented directly in the object. On the other hand, it would be more ‘Maxish’ if the object would simply translate every integer and/or float value to a string when it comes to attribute values. To be honest, this is something that I missed from my mind when I created the object. But I’ll take a note and add this as a feature to the next release. Until then, I suggest you to convert your numbers to symbols (using the [tosymbol] object) and use those symbols as attribute values.

Thanks for the feedback,
Ádám


Viewing 25 posts - 1 through 25 (of 25 total)