27

I have a project where I'm using RelaxNG (jing) to validate xml. I like the syntax for RelaxNG, but most of the tools that I have work with XML schema (actually, I don't think I have a tool that does, other than jing). Am I making a design and future support mistake by using RelaxNG when most of the support seems to be around XML schema? Should I just stick with RelaxNG and make everyone else learn it (kicking and screaming if necessary, j/k)? Should I switch to xml schema because of tool support?

Thanks.

jmq
  • 10,110
  • 16
  • 58
  • 71

5 Answers5

19

The answers is a bit cliche: it depends.

On what, you might ask? On tools that your users will probably be using. And if you depend on your users, you might lose them if lack of good tools will drive them away. Since XML schema is, from my experience, very widely used, you might want to reconsider your decision on going forward with Relax NG. It is nicer and more easily understood than XML schema, but that doesn't mean it will make your project successful.

If you want to risk a bit, go ahead using Relax NG. And during every step of your development, try converting Relax NG to XML schema using a tool like Trang. Just in case you decide one day that Relax NG isn't worth it and you know you have a reasonable backup.

darioo
  • 46,442
  • 10
  • 75
  • 103
  • 1
    Good answer. The other problem with jing is the support level. Some of the code for jing/trang have not been updated for a couple of years. – jmq Feb 14 '11 at 18:28
  • 4
    Worth pointing out that Jing and Trang are under development again now. – Nic Gibson Feb 15 '11 at 16:19
  • 2
    In addition, there are very few bugs in jing; James Clark makes way fewer mistakes than typical programmers. Trang has problems with the XSD output, but otherwise is pretty correct also. The metric "If it's not changing, it's dead" isn't appropriate for this quality of code. – John Cowan Jul 23 '14 at 22:05
  • @JohnCowan I can't help but suspect that those problems with the XSD output are caused by XSD being a huge mess more than anything else. – SamB Apr 16 '19 at 02:18
8

I agree in that it depends on exactly what you need to use schemas for. Here is one more point: if all you need is validation, yes, just go with RelaxNG: it is good for that purpose.

But if you plan on doing data binding (like JAXB), or other kinds of code generation tasks, XML Schema is (unfortunately...) much better choice, since it is more designed towards object-to/from-xml approach than RelaxNG. And conversely not all that good for XML validation; especially considering added complexity. In fact one could call XML Schema a type system more than schema for XML.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
8

Writing slightly limited flavors of RELAX NG and then using Trang to automatically convert to XSD (which we never touch or look at) works very well for us.

John Cowan
  • 1,497
  • 12
  • 13
  • 1
    I should add that we always make sure to validate at least one document against the XSD (jing will do this, using Xerces under the covers) to make sure Trang has not generated an XSD with UPA violations or other XSD errors, as it sometimes will. – John Cowan Mar 01 '11 at 19:20
7

It all depends on who you have to convince. Your analysis is quite correct: RelaxNG is a better language for validation but it has far less tool support. So what tools do you actually need?

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
2

schematron is also another reasonable option, with powerful xpath based validation...

however, my team generally builds everything in Relax/NG compact (for beautiful readability) and convert as necessary to XSD (e.g. for lib based validation), and ignore the XSD otherwise.

:)

this just works.

j03
  • 161
  • 1
  • 5
  • We use schematron as additional schema, not a replacement of RELAX NG or XSD. Schematron is great in providing scenarios (called phases), which we use to specify specific content conditions. For example, if you have to handle situation, that some important attributes might be in corner cases missing, you must permit that in main (RELAX NG or XSD) schema, but may provide Schematron phase "missing content" and another "content present" making sure, your samples are properly behaving in those different scenarios. – Jan Vlcinsky Sep 14 '15 at 20:28