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?
The trouble here is that xs:import/@schemaLocation
is not the same as xs:schema/@xsi:schemaLocation
:
xs:import/@schemaLocation
has to be a URI to the schema location, butxs:schema/@xsi:schemaLocation
has to be a set of namespace-URI pairs.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] 删除。
我来说两句