Max and XML
Does anyone knows about the ability of Max to interpret xml datas?
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 !
Ok, thank you, I’ll have a look on that, which might take me some time ..
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?
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 :
----------begin_max5_patcher---------- 3696.3oc6ck0iqZjE94t+Ufrl6SiusoJ1uRiTVFMizjISdHJRynzQVXnZaxE CV.tWRT9uO0FX.yRYZJLNI2qTaJLFNmuyVsbpC+582sXS7qnzEJeR4GUt6te 896tidJxIti29tE6ce0KzMkdYK1bLKKNZwR1WEcbePTHJi9c.9IO3l4sKHZ6 5DjWF6dCzfOntTAXBHe.Uy+qxOw+MA9z6d7le9ifR273iY0u6rSk81AD6VuX iaz1EJ+D4a+s6um7mkBxKOEFieF4OtmhixRC9E5sEPH2KjEglDtRSmxh5vNY Q8xOzH28zG5huLIvMrYtG1F2i4A2rEKeOvPD5ELQk+byPulwPmj38ouseSbX iHj5fQHfN4CSlFgcyHjykBPspdLLLwKd+dTT1YfhebDR4kfrcJ9wuDgwdekU JIHW+wRKhYgj+gQmVJZWJHoN.jXXF7V.gs2gSl8daB0+629uUvLPneBJ5Q7+ Ci8byBhwGklQOXcfO9r3CyN5iHeezV9gwaRQIOytnrf8Mbl0IO4YCgOF8BxM aGJ4wnLz9CnD2riIn0oYIXfict0Ow+z6wnDD4w8LZ8NLf6Gj8F92GD4Wb8zF 9AI4Gg1lfPo7V6Oriez1ioYrlGRPookehEmX+lRMBvLsO5kCwAQYEWZwIdpz wXhbGliv+BezqEWZoS8TkVdLJh.ygU3B1YvW7yAoAaBBw7J4hK0ZePtDKLHB 4EeLhJ1z.iiaICVrISCpFKTi5ixTqYkUC0ovlqME0iG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ttV4bSVWqF ZvVlILzjOsGrty0XKCihqTV0UJc4Vi.MYtq3uYTO03ZyNf4UrNnvEGkAVorx M10XkQPcmhVW6R+0.Ur3g9fPKlIRQCYxO.A4Gv7plfIjXXlU0cDseTvYFcad S1WagKhWV2n0vK37qFdIhyDn8P6hg4C1ZZZ55mFcryowJKS1BJwRSFzxlVAB MLKXKMGqIgstEqTbB2oh4UkTFbEpqr+YA8ZbdKdid0c+gPT5mFqWh2lr2LOz o6vRsyhxkwU80W9t33TjxaXkYkvXOptZyff9ECBrY4lsRK5msSVqfAlSAFPX Zjev4fv27u9GeSi7rc27rWXf2mIuraDoDsw1jK7WMssoKz7Kz8+IJB8ray.A e0lV7Yza0ojtV7oR4wwHoI8ePun7+hS9rxeSoU77xMjfP1Bgxpug.PmlRZfo PMp55qcB.dbw+HIfrnhJe4wsj4mBfo2OY.9jppxGU0UUebQOFV013FN5Npvk MbP4pGXSKEWi.I6ErHzlaHpWOWaq.jZWJP1tN2fTxZCiaUyZZ.Q.empw.QC0 NwP8YJF93Bx1g+ppLxKnabbT2pSbzb1hieabZV3aJecX7Q+2tt.pZI7DvVi8 VAT6qLf1RUU8699u9ir7mbUdlPsJCs+vZOkUorBm15.ekUwaRQIOyZSpgXqS dxy9ToM8ZT9UgrWxxZ750QKgmzUuTf2nqH40RkpQLTtOZaBBkp3gB8BNlNV8 Il0OXMV4HywpSnBbM6T7WgsqiiHcj4q9tuej6HC+szoZmcjQG9dXe5crZZbv Pi5inkiIcmt.sM36JS814Cgs4gudl.RTRRWU.ZRqxK.i9oI.60.A+UofpYQq wfXA8QrlWHwpxbtvoV73pFSpE1G0pegTqCnD1B4q5wXQsZ8QsZWF0BY6gDN0 paYOVTqlo.psNSpkDTDq6pKOg7oInHzDX5oo9LhuBvTeVpSLJADPxUy48kQS 3F+18+efQghy2 -----------end_max5_patcher-----------
If you know Java at all you can use JDOM. I’ve found this quite useful in parsing XML within Max.
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:
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 ?
It’s a recent addition. Have you reloaded his library? If not, contact me at firstname.lastname@example.org and I’ll send you a copy. Please let me know what platform you’re on.
yes, the sadam objects on his website are older (from december 2010). any news on updates would be fantastic.
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 ; )
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,
Looks great! thank you!
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.
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,
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,
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 .
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 ?
Thanks a lot.
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?
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…
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,
@ Luigi: would you mind giving me some hints (or code snippets) about how to use the ext_xmltree API?
sure, no problem, email me offline at:
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.
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,