1
votes

I need to be able to validate an XML file against an XSD even when there is no Internet connection. My XML file correctly access the XSD and validates (or not) per the contents of the XSD when I access the XS namespace via the usual URL as below:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">  

However, I get error messages (Incorrect definition for the root element in schema" when I try to access a local version of XMLSchema. I downloaded the file from the website per the usual instructions for doing so and saved it as schema2.xsd. I verified that the file URI in the code below works properly by pasting the URI into my browser and the contents of the file loaded as expected. Everything else in my code is identical regardless of whether I try to access XMLSchema with the URL or the File URI (except of course for the one line of code in question).

<xs:schema xmlns:xs="file:///C:/delphi studies/schema/schema2.xsd" elementFormDefault="qualified">

I am sure there must be an easy way to do this, but I just can't get it right despite a lot of googling and experimentation.

1

1 Answers

2
votes

You do not have to be online to validate an XML document with an XSD. In general, an XML namespace URI does not have to be retrievable. This includes http://www.w3.org/2001/XMLSchema, the namespace name used in the XSD vocabulary to name schema components themselves. Think of it less as a retrievable URI and more of lexical extension of component names. By changing xmlns:xs to file:///C:/delphi studies/schema/schema2.xsd, you're effectively renaming every component that uses the xs prefix. You neither need nor want to do that.