The bare minimum to know about RELAX NG

I know what you’re thinking: who uses XML these days! But maybe you do, and maybe you want to validate your XML. One of your options is to use RELAX NG. I spent a moment today to learn about it and here’s what I know.

RELAX NG has two syntaxes, the XML (“regular”) syntax and the compact syntax. If you’re writing RELAX NG by hand, you likely want to use the compact syntax. If needed, you can use Trang to convert the compact syntax to XML. For the record, the compact syntax looks like this:

# HTML goes something like this, I think?
element html {
  attribute lang { text }?,
  element head {
    element title { text }
  element body {
    element h1 { text }* &
    element p { text }*

You could check your XML file with Jing:

jing -c your_schema.rnc your_xml_file.xml

RELAX NG Compact Syntax Tutorial is a good source for learning. I also wrote a RELAX NG cheatsheet.

Comments or questions? Send me an e-mail.