xml – 没有匹配的全局声明可用于验证根
发布时间:2020-12-16 01:54:28 所属栏目:百科 来源:网络整理
导读:背景 使用模式验证XML文档。 问题 问题的最简单形式显示在两个文件中。 XML文档 ?xml version="1.0"?recipe xmlns:r="http://www.namespace.org/recipe"r:description r:titlesugar cookies/r:title/r:description/recipe XSD文档 ?xml version="1.0" encodi
背景
使用模式验证XML文档。 问题 问题的最简单形式显示在两个文件中。 XML文档 <?xml version="1.0"?> <recipe xmlns:r="http://www.namespace.org/recipe"> <r:description> <r:title>sugar cookies</r:title> </r:description> </recipe> XSD文档 <?xml version="1.0" encoding="utf-8"?> <xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:r="http://www.namespace.org/recipe"> <xsd:complexType name="recipe"> <xsd:choice> <xsd:element name="description" type="descriptionType" minOccurs="1" maxOccurs="1" /> </xsd:choice> </xsd:complexType> <xsd:complexType name="descriptionType"> <xsd:all> <xsd:element name="title"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:minLength value="5" /> <xsd:maxLength value="55" /> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:all> </xsd:complexType> </xsd:schema> 错误 来自xmllint的完整错误消息:
题 什么是正确的语法(或缺少什么模式属性),以确保给定的模式可以用于成功验证给定的XML文档?
您需要更改XML实例。您当前的一个说,它在命名空间
http://www.namespace.org/recipe中寻找一个名为description的类型。但是,在该命名空间中公开的唯一类型称为recipe和descriptionType。
因此,在XSD模式中定义一个名为description的类型,或者更改实例,以便正确引用配方类型: <?xml version="1.0" encoding="utf-8"?> <r:recipe xmlns:r="http://www.namespace.org/recipe"> <description> <title>sugar cookies</title> </description> </r:recipe> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |