see whatever…

jump to menu

March 2, 2008

Namespaces are bad but just not bad enough?

Filed under: RelaxNG,XML — see @ 1:15 pm

namespaces are one of the arguments people keep pushing when they want to reject XML (as whole or not). That was the first argument Dave Winer threw on RSS 1.0 back in 2000 and last year at XTech 2007, this was again one of the main arguments the WHATWG threw against XHTML 2.0. And people keep doing that because they’ve noticed that we can’t seriously deny that XML namespaces are insane and because we’ve written it many times in the past

–Eric van der Vlist on the xml-dev mailing list, Tuesday, 12 Feb 2008 20:31:19

via http://www.cafeconleche.org/

Every now and then people seem to argue against namespaces but it seems there is no better alternative just yet:

Compare with (W3C) DOM: DOM is bad, really bad, and so people went and invented something better: JDOM, dom4j, XOM etc for Java; Amara, ElementTree for Python; see your favorite XML tool for your language and even DOM based wrapper libraries like jQuery (which does more but can be seen as a DOM replacement) for Javascript used in Browsers which only have access to the DOM.

Compare to (W3C) XML Schema: XML Schema is at least not what it has been hoped for, for some people just a failure. So people went and invented something better like Schematron, Examplotron etc and probably most importantly Relax-NG which is getting more and more support in the last years.

But namespaces? Maybe I am being ignorant to alternative propositions but it seems no one came up with a better solution yet. Of course namespaces are a bit more core XML then DOM or XML Schema but hey, people even suggest improvements for XML 2.0 (see the current discussion on xml-dev).

So I guess namespaces are just not bad enough ;)

April 19, 2007

beautiful XML

Filed under: RelaxNG,XML,XSLT — see @ 8:37 pm

Completely my view too: beautiful XML. Maybe XQuery is not ugly either, but I do not know enough to judge this one.

April 12, 2006

Using the same data in Python and Jython

Filed under: Jython,Programming,Python,RelaxNG — see @ 9:26 pm

I had the problem of needing the same data for some related tasks for which I wrote

  1. a (C)Python script because I used the really great Lingfo – a library to read Excel data with Python together with this Cookbook recipe
  2. a Jython script as I used Jing to validate some XML files with a RelaxNG schema

I may have used other libs which may be available for only one taste of P/J-ython but found these the easiest to use and actually used them for other stuff before so did know how to use them. I could have used Pythons’s lxml but do not know if it validates with the RNC compact syntax or could have used something like Java’s POI to read the Excel but I actually try to minimize the Jython usage as I almost always prefer Python (being faster, 2.4. being much more convenient than Jython’s 2.1 implementation [2.2. still being alpha] etc etc)…

Aynway, so I read data from an Excel sheet with the Python script, read some XML files with the obtained data but needed the same data to do the validation of the XML files with Jython. The XML files themselves are on disk so no problem, the data on the other hand was a bit more complex list of dicts with quite a few information atoms.The solution turned out to be quite simple actually. As for the problem at hand I am able to start both scripts independently (or maybe writing a third shell script which calls both) I put a simple pickle in the Python script and read the same data with pickle in Jython.

Maybe a bit too trivial to actually blog about at all but as I never needed anything like the pickle (shelve, marshall etc) modules and never really saw a use case for them it was actually quite enlightening. I was wondering for some time now how to best integrate Python and Jythons tasks into the same app and this seems like a possibility at least for some cases. And I tried out another module of the very nice and comprehensive stdlib. (Which I missed by the way while doing some other work in PHP ;)

March 15, 2006

RelaxNG Test with Selenium (a bit contrived I know ;)

Filed under: Programming,Python,RelaxNG,Web,XML — see @ 12:09 am

Maybe it is easier to validate an XML file with RelaxNG with a simple program. But as I wanted to try something with Selenium anyway (and other tests – UI tests – need Selenium) I build something a bit around.

I built a servlet which did a RelaxNG validation on a given XML file and prints out a “Validates: True” message with a log of errors and the XML source. The XML file to validate itself can be given via an URI in a request parameter so that the validation servlet would fetch the XML via HTTP itself. Selenium than could test the output of the validation servlet.

So the first step is the XML server which is just used as a kind of webservice to access files on a machine. This server is a very simple Python server based on BaseHTTPServer. Could have been (as the following one) a Java servlet but I just found this approach much easier than working around servlet limitations. I used port 8081 but that could have been any other of course.

The second step is the validation servlet which runs in a standard tomcat just because Jing is a Java lib and therefore easiest to use with Java. Actually the servlet is written in Jython but only because I am much more comfortable with Jython than with raw Java. I use the standard Tomcat 8080 port.

The third step – Selenium – actually runs in a Twisted server which enables the Selenium tests to work with any given server as no cross site scripting issues arise. The setup for this is very nicely explained in Web app testing with Python part 2: Selenium and Twisted. I used port 8082 here as Tomcat already uses 8080.

The test itself just does 2 Selenium commands:

1. open the test URL on the validation server, e.g. (not escaped)
- Twisted URL: http://localhost:8082/AUT/00000A/…
- followed by path: …/http/validationserver:8080?…
- followed by query param: …?xmlURI=http://xmlserver:8081/example.xml

2. verifyTextPresent “Validates: True”

So quite an effort just to do a XML validation but on the other hand nice to do all tests in just one tool.

Only annoying thing is that the Twisted Selenium server needs Twisted 1.3.0 and does not work with the current 2.2.0 version. Maybe that was the reason that running tests on about 300 files do fail after about 25, seems to stress Twisted (or my laptop ;) too much. I guess I am not skilled enough to bring Selenium to work on Twisted 2.2.0 but maybe I try. If anybody has a solution already, let me know

Alltogether quite fun doing admittedly a bit contrived but working setup and at least I did even some more practive setting up simple but effective servers. I find working in such a way more comfortable than writing a standalone program which in the end cannot be split into components which the described setup actually is. Fact is that I only wrote the XML server from scratch but even that is used for other stuff, so perfectly separated components but working together quite nicely…

July 2, 2005

RelaxNG Documentation

Filed under: RelaxNG,reStructuredText — see @ 6:58 pm

There is an new mailing list about my favourite schema language (not that I have used many and thoroughly but anyway), the RelaxNG user list.

A current topic is schema documentation. When I wrote my first bigger set of RelaxNG schemas I actually thought about that quite a bit as I had to do at least some kind of docs for the client and also the programmers of the framework using that specific XML format described by the schema. For now I simply used simple comment and basic annotations (“# comment” or “## annotation” in the compact syntax which I prefer). People accustomed to DTDs probably understand the compact syntax without knowing RelaxNG, at least the more simpler parts of it. I also used Oxygens RelaxNG diagrams to give a visual overview of the XML format.

I did notice however that a better documentation with maybe examples and more stuff would be handy, even a simplified version for people actually using the grammar and not building on the grammar would be quite useful at times. Therefor at first I though of simply adding a RelaxNG part to my own XSLdoc app which does about the same for XSLT what Javadoc does for Java. In documentation for RelaxNG (having a compact syntax by itself) would actually be quite nice to use the Python Docutils wiki like syntax I use for my XSLT documentation.
I do know the [ ] syntax for structuring Relax annotations but I think I’d prefer a simple and much more readable wiki like syntax to a more explicit-markup like syntax like relax [] stuff.
From a Docutils documented RelaxNG schema it would be easy to generate a set of XHTML documentation (or other formats of course) like the ones Javadoc generates. I still quite like that docs even that I do not use Java that much. They come in handy when using a Java library from e.g. Jython or simple to look what a particular lib does. Actually I prefer Javadocs to most Python documentation as it is much more standardized.

I think using wiki-like markup is easier for most people than actually using more explicit markup like XML or HTML.

Well, at least a very interesting new mailing list which I guess I will follow quite regularly. (BTW, all XML related mailing list seem to have only a small set of people actually using it, you see the same names all over again. Wonder what other people use to keep informed and ask questions…)

Powered by WordPress