1

I have recently introduced myself to XML Schema (XSD), and I am struggling in finding answers to a few fundamental questions about them:

  1. What is the proper way to link an XML document to its XSD schema?
  2. How are XML documents actually validated? After allegedly linking my XML document to a schema I never actually saw any document errors generated when the schema was violated.

I've been struggling in finding answers to these questions and thank responders in advance for their contributions :)

Alan
  • 2,109
  • 5
  • 25
  • 28

2 Answers2

2
  1. You can use the xsi:schemaLocation attribute. However, in my view it's inherently dangerous. If you need to validate a file, that's often because you don't trust it to be valid, and if you don't trust it to be valid, why should you trust it to identify its own schema? All schema validation APIs allow you to nominate a source document S and a schema K and say "validate S against K".

  2. There are many APIs for invoking schema validation. In some cases the operation is integrated with XML parsing, you just set an option on the XML parser. But generally you have to ask for validation, it won't happen automatically.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
1
  1. You can generate the xml from the xsd itself, or you can create it yourself and validate it. see: What is the difference between XML and XSD?
  2. That is implentation related, here is an example on Java: What's the best way to validate an XML file against an XSD file?
  3. I'm not sure what is the question here really. if you want to display xml to the user, I don't see the benefit in trying to show it as html. it should be shown as XML , how it is shown depends on the viewer being used: browser/notepad++/XmlPad etc...
Community
  • 1
  • 1
omer schleifer
  • 3,897
  • 5
  • 31
  • 42
  • Thank you for your answers to 1. and 2, they were extremely helpful. Part 3 was a misguided question. What I meant to ask is how XML data is generally displayed in the context of an HTML document, however I own a copy of google so I can look that up :). – Alan Jun 19 '13 at 05:15