简体   繁体   English

XML 文件的 XML 架构定义 (XSD)

[英]XML Schema Definition (XSD) for XML files

How can I check whether a XML file uses a XML Schema Definition (XSD)?如何检查 XML 文件是否使用 XML 架构定义 (XSD)? For example, if you decompress a signed odt file (LibreOffice or OpenOffice text document), in the directory META-INF is the signaturefile documentsignatures.xml .例如,如果您解压已签名的 odt 文件(LibreOffice 或 OpenOffice 文本文档),则 META-INF 目录中的签名文件为 documentsignatures.xml In this file the attribute xmlns defines a default namespace for the elements <Signature> and <document-signatures> .在此文件中,属性xmlns为元素<Signature><document-signatures>定义了默认命名空间。 There is neither a reference by the attribute xmlns:xsi to the XML Schema Instance (XSI) namespace "http://www.w3.org/2001/XMLSchema-instance" nor a reference by the attribute xsi:schemaLocation to the XML schema file xmldsig-core-schema.xsd .属性xmlns:xsi既没有引用 XML 模式实例 (XSI) 名称空间"http://www.w3.org/2001/XMLSchema-instance"也没有引用属性xsi:schemaLocation到 XML 模式文件xmldsig-core-schema.xsd As a result, the entire content of the documentsignatures.xml file should not be validated under any scheme.因此,不应在任何方案下验证 documentsignatures.xml 文件的全部内容。 Is that correct?那是对的吗?

Here are the first lines of the correspnding XML document documentsignatures.xml :以下是相应 XML 文档documentsignatures.xml的第一行:

<?xml version="1.0" encoding="UTF-8"?>
<document-signatures xmlns="urn:oasis:names:tc:opendocument:xmlns:digitalsignature:1.0">
    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#" Id="ID_006900630020002d0084000e004a008b009b00a6006f004b007c007b002d007f">
        <SignedInfo>...

Greetings你好

Kaleun卡伦

"...How can I check whether a XML file uses a XML Schema Definition (XSD)?..." “...如何检查 XML 文件是否使用 XML 架构定义 (XSD)?...”

(1) You cannot, if there is no embedded reference in an XML file by the attribute xsi:schemaLocation to the XML schema. (1) 如果 XML 文件中没有通过属性xsi:schemaLocation嵌入到 XML 模式的xsi:schemaLocation ,则不能。

(2) Though, whatever API is in use, it can still validate against some XSD schema that is not mentioned in the actual XML file. (2) 但是,无论使用什么 API,它仍然可以针对实际 XML 文件中未提及的某些 XSD 模式进行验证。

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

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