简体   繁体   中英

How to reference XSD in XML for W3C Markup Validation Service?

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, eg 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?

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*(((([az][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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM