1

I would like to create a XML that follows the XML schema http://www.oid-info.com/oid.xsd . This XSD should be somehow referenced in the XML file, so that a tool like the https://validator.w3.org/ can check it to find errors in the semantics of the data, e.g. when an email address is invalid.

First, I tried it this way:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<oid-database xmlns="http://www.oid-info.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oid-info.com/oid.xsd">
<submitter>
....
</submitter>
<oid>
....
</oid>
</oid-database>

The W3C Markup Validation Service says:

No DOCTYPE found! Checking XML syntax only. The DOCTYPE Declaration was not recognized or is missing. This probably means that the Formal Public Identifier contains a spelling error, or that the Declaration is not using correct syntax, or that your XML document is not using a DOCTYPE Declaration. Validation of the document has been skipped, and a simple check of the well-formedness of the XML syntax has been performed instead.

Ok, so I tried to use DOCTYPE

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE oid-database>
<oid-database xmlns="http://www.oid-info.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oid-info.com/oid.xsd">
<submitter>
....
</submitter>
<oid>
....
</oid>
</oid-database>

Now the W3C Validator says:

Line 2, Column 23: no internal or external document type declaration subset; will parse without validation

I do know what a DTD is, and I have worked with DTDs in the past. I know that a DTD is missing here. But I want to check against a XSD, and not against a DTD.

What do I have to do to make it work?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Daniel Marschall
  • 3,739
  • 2
  • 28
  • 67

1 Answers1

2

That W3C Validator will check well-formedness and will validate against a DTD; it doesn't validate against an XSD. You'll have to use another on- or off-line validator.

Also, here is how your XML file should look to hint that it should be validated valid against the OID XSD:

<?xml version="1.0" encoding="UTF-8" ?>
<oid-database xmlns="http://oid-info.com"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://oid-info.com 
                                  http://www.oid-info.com/oid.xsd">
  <submitter>
    ....
  </submitter>
  <oid>
    ....
  </oid>
</oid-database>

See also: How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

Note that those XSDs appear to have their own issues, including:

[Warning] xhtml-light.xsd:8:36: schema_reference.4: Failed to read schema document 'xml.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

[Error] oid.xsd:91:46: InvalidRegex: Pattern value '{?\s*(((([a-z][a-zA-Z0-9-]\s((\s*(0|[1-9][0-9])\s))?|(0|[1-9][0-9]))){2,}\s)|((0|[1-9][0-9])(.(0|[1-9][0-9]))))\s}?' is not a valid regular expression.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thank you very much for this information. Which tool did you use to validate this XML ? The tool http://www.freeformatter.com/xml-validator-xsd.html does require that you enter the XSD manually. I would like that it reads it directly out of the XML plus downloads further referenced XSDs (like the xhtml-light.xsd) automatically. – Daniel Marschall Aug 24 '16 at 09:30
  • I don't use an online validator, but [this one](https://devutilsonline.com/xml/validate) would seem to meet your requirements; I use an off-line, Xerces-J-based validator. – kjhughes Aug 24 '16 at 12:00