Importing XML Schema

Bryan

EDIT: Made slight change. I think I got a little closer, but still not working. All current info is as follows:

I successfully created an XSD file to validate an XML file, however I would like to split up the XSD file into another file. I believe I need to use an import element in the XML file to do that, but I am struggling to get it to work. Here is what I have right now at the top of the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<presentations xmlns="http://www.brett.com/presentations"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.brett.com/presentations presentations_vb.xsd"
>

Here is the top part of the main XSD file:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.brett.com/presentations"
targetNamespace="http://www.brett.com/presentations"
elementFormDefault="qualified">

<!-- Here is the line in question -->
<xs:import namespace="http://www.brett.com/presentations/topic" schemaLocation="http://www.brett.com/presentations topic_vb.xsd" />

Here is the new XSD file that I am trying to import:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.brett.com/presentations/topic"
targetNamespace="http://www.brett.com/presentations/topic"
elementFormDefault="qualified">

<!-- Topic Element -->
    <xs:complexType name="topicType">
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute name="genre" use="required">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:enumeration value="ART" />
                <xs:enumeration value="Music" />
                <xs:enumeration value="Science" />
                <xs:enumeration value="Technology" />
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>

    <xs:element name="topic" type="topicType" />
</xs:schema>

Everything was well-formed and validated prior to breaking up the XSD into two files. I'm pretty sure I'm importing it wrong, but I can't figure out the proper way. I'm getting the following error when trying to validate the XML file (the XSD files still validate): "FatalError at line 0, column 0: unsupported protocol in URL"

Can anyone help?

kjhughes

The trouble here is that xs:import/@schemaLocation is not the same as xs:schema/@xsi:schemaLocation:

So, remove the namespace part of your xs:import/@schemaLocation value and leave the URI to the XSD.

Specifically, change:

<xs:import namespace="http://www.brett.com/presentations/topic"
           schemaLocation="http://www.brett.com/presentations topic_vb.xsd" />

to:

<xs:import namespace="http://www.brett.com/presentations/topic"
           schemaLocation="topic_vb.xsd" />

(or whatever your actual URI for topic_vb.xsd is, of course.)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Is there a xsd or xml schema for job in Jenkins?

来自分类Dev

Oracle XML Schema验证日期模式错误

来自分类Dev

XML Schema是SGML DTD的子集吗?

来自分类Dev

如何配置solr schema.xml

来自分类Dev

推动schema.xml中的“ ON UPDATE”

来自分类Dev

如何使用XML Schema扩展属性?

来自分类Dev

MarkLogic是否完全支持XML Schema 1.1?

来自分类Dev

如何配置solr schema.xml

来自分类Dev

使用xerces for Android进行XML Schema验证

来自分类Dev

在SolrCloud中重新加载schema.xml

来自分类Dev

验证XML-Schema(xsd)错误

来自分类Dev

订购类似xml schema java中的列表

来自分类Dev

推进schema.xml中的“ ON UPDATE”

来自分类Dev

Oracle XML Schema验证日期模式错误

来自分类Dev

使用 RelaxNG-schema 验证 XML 的问题

来自分类Dev

针对 Schema lxml 的 Python XML 验证

来自分类Dev

SOLR-为XML数据配置schema.xml

来自分类Dev

XML Schema和XML放在一个文件中?

来自分类Dev

从 json 中引用 JSON Schema 类似 XML 引用 XML 模式

来自分类Dev

如何使用XML Schema重用另一个Schema / Namespace(即XHTML)中的元素?

来自分类Dev

什么时候值得创建XML Schema(XSD)?

来自分类Dev

Solr集合-如何使用vi修改schema.xml

来自分类Dev

如何转换不同用途的基本XML Schema?

来自分类Dev

XML Schema 1.0中是否有<assert>的替代方法

来自分类Dev

schema.xml中的_root_字段是什么?

来自分类Dev

从mongodb自动为Solr创建schema.xml

来自分类Dev

在XML :: COMPILE :: SCHEMA中附加标签或多个标签

来自分类Dev

如何针对XML Schema(XSD)或RelaxNG验证JSON?

来自分类Dev

如何使用XML Schema验证DD MM YYYY日期?