XML Schema Import
-
I am attempting to create a generic xml schema file that defines element type restrictions. That file is then imported into my additional xml schemas, which make use of the defined types. Here is what I have. General Formatting File
<?xml version="1.0" encoding="utf-8" ?> <xs:schema id="GeneralFormatting" targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" elementFormDefault="qualified" xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Define format restriction --> <xs:simpleType name="UserName"> <xs:restriction base="xs:string"> <xs:pattern value="([a-zA-Z0-9])*"></xs:pattern> <xs:whiteSpace value="preserve" /> </xs:restriction> </xs:simpleType> </xs:schema>
XML Schema<?xml version="1.0" encoding="utf-8" ?> <xs:schema id="WTNManagement_XSD" targetNamespace="http://localhost/XMLWebServices/Management.xsd" elementFormDefault="qualified" xmlns:tns="http://localhost/XMLWebServices/Management.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /> <!-- definition of elements --> <xs:element name="Management" id="Management"> <xs:complexType> <xs:sequence> <!-- File Sequence number, must be unique --> <xs:element name="SeqNum" type="xs:integer" /> <!-- User making request --> <xs:element name="UserName" type="xs:UserName" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
This code isn't working could someone point me in the right direction. Thanks Jason W. -
I am attempting to create a generic xml schema file that defines element type restrictions. That file is then imported into my additional xml schemas, which make use of the defined types. Here is what I have. General Formatting File
<?xml version="1.0" encoding="utf-8" ?> <xs:schema id="GeneralFormatting" targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" elementFormDefault="qualified" xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Define format restriction --> <xs:simpleType name="UserName"> <xs:restriction base="xs:string"> <xs:pattern value="([a-zA-Z0-9])*"></xs:pattern> <xs:whiteSpace value="preserve" /> </xs:restriction> </xs:simpleType> </xs:schema>
XML Schema<?xml version="1.0" encoding="utf-8" ?> <xs:schema id="WTNManagement_XSD" targetNamespace="http://localhost/XMLWebServices/Management.xsd" elementFormDefault="qualified" xmlns:tns="http://localhost/XMLWebServices/Management.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import namespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /> <!-- definition of elements --> <xs:element name="Management" id="Management"> <xs:complexType> <xs:sequence> <!-- File Sequence number, must be unique --> <xs:element name="SeqNum" type="xs:integer" /> <!-- User making request --> <xs:element name="UserName" type="xs:UserName" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
This code isn't working could someone point me in the right direction. Thanks Jason W.You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd" and then have
-
You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd" and then have
Something like this? Generic Formatting XML Schema
<?xml version="1.0" encoding="utf-8" ?> <xs:schema id="GeneralFormatting" targetNamespace="http://localhost/XMLWebServices/GeneralFormatting.xsd" elementFormDefault="qualified" xmlns:ns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Define format restriction --> <xs:simpleType name="UserName"> <xs:restriction base="xs:string"> <xs:pattern value="([a-zA-Z0-9])*"></xs:pattern> <xs:whiteSpace value="preserve" /> </xs:restriction> </xs:simpleType> </xs:schema>
Additional XML Schema<?xml version="1.0" encoding="utf-8" ?> <xs:schema id="WTNManagement_XSD" targetNamespace="http://localhost/XMLWebServices/Management.xsd" elementFormDefault="qualified" xmlns:tns="http://localhost/XMLWebServices/Management.xsd" xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import schemaLocation="http://localhost/XMLWebServices/GeneralFormatting.xsd" /> <!-- definition of elements --> <xs:element name="Management" id="Management"> <xs:complexType> <xs:sequence> <!-- File Sequence number, must be unique --> <xs:element name="SeqNum" type="xs:integer" /> <!-- User making request --> <xs:element name="UserName" type="gns:UserName" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Thanks Jason W. -
You shouldn't be using the xs: prefix for the UserName type in the second schema, as the xs is for the schema namespace. You probably should define another xmlns for the imported namespace ie xmlns:gf="http:....GeneralFormatting.xsd" and then have
Here are the details of the error message I’m getting.
Type ‘http://localhost/XMLWebServices/GeneralFormatting.xsd:UserName’ is not declared. An error occurred at ...
Hope that helps. Jason W. -
Here are the details of the error message I’m getting.
Type ‘http://localhost/XMLWebServices/GeneralFormatting.xsd:UserName’ is not declared. An error occurred at ...
Hope that helps. Jason W.In your first schema you should change the xmlns:gns="http://localhost/XMLWebServices/GeneralFormatting.xsd" to xmlns="http://localhost/XMLWebServices/GeneralFormatting.xsd" so that all types declared are in that namespace, otherwise you would have to put the gns prefix on all type names...