Search code examples
xmlrelaxngrelaxng-compact

Input documents againts relax ng


I am currently reading about XML and Relax NG, and I found one question in one notebook which got me confused. The question is: "Explain an application where we have a situation that does not require input documents to be valid (for example against a RelaxNG schema, etc.) but instead merely well-formed.". Can anyone help? Thanks.


Solution

  • RELAX NG is a schema language for XML documents. You can use it to specify how a given XML document must be structured. E.g. you could create a RELAX NG schema to specify how to store customer data in XML files, which could include rules that require a name and address for each customer, and allow for (but not require) a customer phone number. An XML document that follows the rules laid out in such a schema is said to be valid (against that particular schema).

    Well-formedness is a much more basic requirement, and just means that the XML document follows the rules of the XML format itself. Making sure your XML documents are well-formed ensures that they can be read by any XML parser, and validated against any XML schema.

    Schema validation becomes especially important if you e.g. collect XML documents from external and/or multiple sources and want to make sure that these documents can all be processed with the same computer code. If you generate XML documents yourself with one tool and process them yourself with another, you might not benefit much from a schema, but you still want these documents to be well-formed to make them parsable with standard XML tools.