After spending so much time generating my XML data I decided that I wanted to be able to see it presented in a user friendly fashion. Enter XML Stylesheets.
Boy what a frustrating time I had getting these to work. I found two big problems that took some time to solve.
The first problem that I had was originally the browser complained about my stylesheet because the web server reported its mimetype as text/xml and suggested it should be text/css. I reconfigured the webserver thinking this was the problem (of no output) but found that the browser then tried to interpret my XML stylesheet as CSS and produces a multitude of errors as a result.
So after changing it back (and still not working) I finally hit upon the solution. The web server has to report the file as text/xml but the source XML file has to tell the browser that it is text/xsl so the browser knows how to interpret it.
Secondly, I found that although I wrote a valid stylesheet for reasons that I couldn't fathom it produced either no output or wrong output. The browser will only complain at you when your stylesheet is not valid or well formed but if it passes these two tests there is no way to ask it what is wrong with the stylesheet.
So then I had to start with the most basic stylesheet and work my way up from there. One of the things that caught me out was the matching system. If for some reason your templates didn't match everything in the XML file the the browser would just dump any XML that was left over. This was a huge source of frustration as I had the impression that anything not matched would be ignored.
I did finally get a reasonablly working stylesheet:
https://netdb.alphawest.com.au/xml/netdb-style.xsl
Now it is a simply task as I add a new node to the XML output to create a new template into the stylesheet and get it parsed as the appropriate place. Simple now that it works!
Friday, 27 June 2008
XML and Schemas
I have embarked upon a project to output XML data from my intranet application. For what end I don't know yet but I thought it would be a useful exercise to have the ability to have my data in XML format.
My first attempt was the usual ad hoc method of simply outputting some XML but as I progressed I realized that I had no clear picture of what the XML should look like.
So this time around I have started with the other end and begun developing an XML schema.
https://netdb.alphawest.com.au/xml/netdb.xsd
I have done this with the assistance of Eclipse which has a nice GUI based tool for generating XML Schema. I now understand how it all hangs together and thus now have a nicely structured schema file describing what the XML form of my data should look like.
It has now become a much easier task to write the PHP code to output XML that complies with the schema. I have yet worked out a method to validate my generated XML against the schema without paying for software. Perhaps someone can recommend something.
My lesson learned from this experience is it pays to design your data first.
The next challenge is to find a useful application of this XML data. I would love to do some semantic web stuff with it but it tends to require RDF formatted data which would throw out the schema and probably require instead an OWL file describing what triples can exist.
I'll keep you posted on that.
My first attempt was the usual ad hoc method of simply outputting some XML but as I progressed I realized that I had no clear picture of what the XML should look like.
So this time around I have started with the other end and begun developing an XML schema.
https://netdb.alphawest.com.au/xml/netdb.xsd
I have done this with the assistance of Eclipse which has a nice GUI based tool for generating XML Schema. I now understand how it all hangs together and thus now have a nicely structured schema file describing what the XML form of my data should look like.
It has now become a much easier task to write the PHP code to output XML that complies with the schema. I have yet worked out a method to validate my generated XML against the schema without paying for software. Perhaps someone can recommend something.
My lesson learned from this experience is it pays to design your data first.
The next challenge is to find a useful application of this XML data. I would love to do some semantic web stuff with it but it tends to require RDF formatted data which would throw out the schema and probably require instead an OWL file describing what triples can exist.
I'll keep you posted on that.
Monday, 2 June 2008
The wonderful world of XSD
I have decided that for reasons that I don't yet understand, I am delving into the world of XML Schemas. From starting out thinking it's a relatively easy thing to describe your data to realizing what a huge task it is, I am now getting the hang of this and hopefully will be able to move on up to OWL once I am done here.
Understanding you data is the first task in creating a good schema definition. I have a standard relational database where I store all the information for my intranet web application. Sounds simply so far. Things start to get complicated when I mention that the database is actually an object relational one and yes I have tables that are inherited from other tables. Then most of these tables are represented at the middleware level by a bunch of PHP classes all inherited from a single parent.
With me so far? So from all that I want to create a schema that describes all the data that I have. Except that not all the data exists in the database and the data fakes some heirarchical information that has to now be represented in XML.
So, as you can guess, I'm having fun so far. I have an idea of the size of the task now and realize that I must spend some time making the right choices so that I end up with a useful and complete model of my data.
Wish me luck.
Understanding you data is the first task in creating a good schema definition. I have a standard relational database where I store all the information for my intranet web application. Sounds simply so far. Things start to get complicated when I mention that the database is actually an object relational one and yes I have tables that are inherited from other tables. Then most of these tables are represented at the middleware level by a bunch of PHP classes all inherited from a single parent.
With me so far? So from all that I want to create a schema that describes all the data that I have. Except that not all the data exists in the database and the data fakes some heirarchical information that has to now be represented in XML.
So, as you can guess, I'm having fun so far. I have an idea of the size of the task now and realize that I must spend some time making the right choices so that I end up with a useful and complete model of my data.
Wish me luck.
Subscribe to:
Posts (Atom)