简体   繁体   English

如何为W3C标记验证服务引用XML中的XSD?

[英]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 . 我想创建一个遵循XML模式http://www.oid-info.com/oid.xsd的XML。 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. 应该以某种方式在XML文件中引用此XSD,以便诸如https://validator.w3.org/之类的工具可以对其进行检查,以发现数据语义上的错误,例如,当电子邮件地址无效时。

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: W3C标记验证服务说:

No DOCTYPE found! 找不到DOCTYPE! Checking XML syntax only. 仅检查XML语法。 The DOCTYPE Declaration was not recognized or is missing. DOCTYPE声明未被识别或丢失。 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. 这可能意味着正式公共标识符包含拼写错误,或者声明未使用正确的语法,或者您的XML文档未使用DOCTYPE声明。 Validation of the document has been skipped, and a simple check of the well-formedness of the XML syntax has been performed instead. 该文档的验证已被跳过,而是对XML语法的格式正确性进行了简单检查。

Ok, so I tried to use DOCTYPE 好的,所以我尝试使用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: 现在,W3C验证程序会说:

Line 2, Column 23: no internal or external document type declaration subset; 第2行,第23列:没有内部或外部文档类型声明子集; will parse without validation 将解析而不验证

I do know what a DTD is, and I have worked with DTDs in the past. 我确实知道DDT是什么,并且我过去曾使用过DTD。 I know that a DTD is missing here. 我知道这里缺少DTD。 But I want to check against a XSD, and not against a DTD. 但我想检查XSD,而不是DTD。

What do I have to do to make it work? 我必须怎么做才能使其正常工作?

That W3C Validator will check well-formedness and will validate against a DTD; W3C验证程序将检查格式是否正确,并将针对DTD进行验证; it doesn't validate against an XSD. 它无法针对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文件的外观,以暗示应根据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? 另请参阅: 如何使用schemaLocation或noNamespaceSchemaLocation将XML链接到XSD?

Note that those XSDs appear to have their own issues, including: 请注意,这些XSD似乎有其自身的问题,包括:

[Warning] xhtml-light.xsd:8:36: schema_reference.4: Failed to read schema document 'xml.xsd', because 1) could not find the document; [警告] xhtml-light.xsd:8:36:schema_reference.4:无法读取架构文档'xml.xsd',因为1)找不到文档; 2) the document could not be read; 2)无法读取文件; 3) the root element of the document is not . 3)文档的根元素不是。

[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 }?' [Error] oid.xsd:91:46:InvalidRegex:模式值'{?\\ 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. 不是有效的正则表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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