Alan
Alan

Reputation: 2129

On XML Schema and Their Uses

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 :)

Upvotes: 1

Views: 103

Answers (2)

Michael Kay
Michael Kay

Reputation: 163322

  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.

Upvotes: 2

omer schleifer
omer schleifer

Reputation: 3935

  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...

Upvotes: 1

Related Questions