Download the whole project in a single zip file (80 KB)
How it works
The idea is, to create a grammar for XRC files, stored in XML, then use that grammar in an XSLT stylesheet to transform the XRC to a validity report in XHTML. All this can be done with just a standard browser.
- instructionsHow to validate your own XRC files
- cssCascading StyleSheets for layout of the HTML
- dtdvalidation by Document Type Definition
- htmloutput files generated by XSLT Processor
- rngRelax NG validation
- xmlXRC grammar and error strings
- xrcsample XRC files to validate
- xrvin-between XML files (pointers to xrc files)
- xslthe XSLT stylesheets
Terminology (attributes vs properties)
The XRC source code and official (unfinished) documentation uses the name 'property' for attributes and vice versa:
<object class="wxSomething"> <node property1="value1" property2="value2">...</node> <attribute>...</attribute> </object>
I have chosen not to follow that convention. It's not XML terminology. What XRC calls a property, is really an attribute:
<object class="wxSomething"> <node attribute1="value1" attribute2="value2">...</node> <property>...<property/> </object>
Limitations
No line numbers
One major limitation of using XSLT is that it will be very difficult or even impossible to include line numbers in the error reports. The XSLT processor sees the XRC document as an XML tree, with no notion of 'line numbers' whatsoever. The solution I propose, is to add a "pseudo-XPath" to the error message, something like:
wxSomeClass(classname)/wxSomeSizer[2]/sizeritem
In most cases I think that should be enough to locate the error(s) in the source file.
Problems with client-side processing
I have chosen to use XSLT 1.0 client-side processing throughout this project. It's the easiest way for the user: you don't need a separate XSLT processor, just a text editor and a browser will do. The downside is, things don't always work the same in every browser. Some browsers don't support XSLT altogether. Also, client-side processing has some limitations - you cannot pass parameters to the stylesheet, and cannot use extensions like exsl:nodeset, and that makes it difficult e.g. to show a "no errors found" message.
Difficulties with datatype checking
Checking for a boolean value would be straightforward (element contents must be '0' or '1') but the other datatypes are not so easy. For example, it would be nice if the validator could check style flags (eg. a wxButton can contain wxBU_LEFT, RIGHT etc flags, but other classes have different style flags). The flags can be combined with '|' chars. Checking these things is a lot easier in XSLT 2.0 than in 1.0, but browsers don't support this yet.
Feedback
Needless to say, all feedback is welcome. If you use the validator and find any bugs, false errors or any other problems, questions or suggestions, don't hesitate to contact me.