![]() |
|
|
|||||||
![]() |
XML - Including element from one schema namespace in another schema namespace |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
How does one say in one schema that one wants an element defined in
another schema. For example, I want to include in the Employee definition, an Address element defined in the schema http://test.org.Address Here is the schema defining the Employee: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://test.org/emp" xmlns="http://test.org/emp" xmlns:addr="http://test.org/Address" xmlns xmlns elementFormDefault="qualified" version="2.0"> <xsd:import namespace="http://test.org/Address" schemaLocation="Address.xsd"/> <xsd:complexType name = "EmployeeType"> <xsd:sequence> <xsd:element ref="Name" minOccurs="1" maxOccurs="1"/> <xsd:element ref="JobInfo" minOccurs="0" maxOccurs="unbounded"/> <xsd:element ref="Salary" minOccurs="0" maxOccurs="1" /> <addr:Address minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> .... </xsd:schema> Here is the definition of the Address: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://test.org/Address" xmlns="http://test.org/address" xmlns xmlns elementFormDefault="qualified" version="2.0"> <xsd:complexType name="addressType"> <xsd:sequence> <xsd:element minOccurs="1" maxOccurs="unbounded" name="Line"><xsd:simpleType><xsd:restriction base="xsd:string"/></xsd:simpleType></xsd:element> <xsd:element minOccurs="1" maxOccurs="1" name="City"><xsd:simpleType><xsd:restriction base="xsd:string"/></xsd:simpleType></xsd:element> <xsd:element minOccurs="1" maxOccurs="1" name="State"><xsd:simpleType><xsd:restriction base="xsd:string"/></xsd:simpleType></xsd:element> <xsd:element minOccurs="1" maxOccurs="1" name="zip"><xsd:simpleType><xsd:restriction base="xsd:string"/></xsd:simpleType></xsd:element> </xsd:sequence> </xsd:complexType > <xsd:element name="address" type="addressType"/> </xsd:schema> This gives me an error message. Note, I have no problems bringing in a type from one schema into another. That is, I created an addressType in the http://test.org/Address name space. I used that just fine to define an element in the http://test.org/emp Schema. I am wondering if there is a way to bring in an element itself from one schema into another. (I also tried writing using the ref attribute, but ref requires a QName, not a NCName. So I got a syntax error message if I was to write <xsd:element ref="emp:Address") Dr. Laurence L. Leff, Ph.D. Associate Professor of Computer Science Western Illinois University 1 University Circle Macomb IL 61455 309 367 0787 mflll@wiu.edu |
|
|
|
|
#2 |
|
Posts: n/a
|
Hi,
First note that XML Schema component names are case sensitive and address and Address are different components. If you want to specify that the content of EmployeeType should contain an element from the http://test.org/Address namespace named address then use <xs:element ref="addr:address"/> Best Regards, George --------------------------------------------------------------------- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com wrote: > How does one say in one schema that one wants an element defined in > another schema. For example, I want to include in the Employee > definition, an Address element defined in the schema > http://test.org.Address > > Here is the schema defining the Employee: > > <?xml version="1.0" encoding="UTF-8"?> > <xsd:schema targetNamespace="http://test.org/emp" > xmlns="http://test.org/emp" > xmlns:addr="http://test.org/Address" > xmlns > xmlns > elementFormDefault="qualified" version="2.0"> > <xsd:import namespace="http://test.org/Address" > schemaLocation="Address.xsd"/> > > > <xsd:complexType name = "EmployeeType"> > <xsd:sequence> > <xsd:element ref="Name" minOccurs="1" maxOccurs="1"/> > <xsd:element ref="JobInfo" minOccurs="0" maxOccurs="unbounded"/> > <xsd:element ref="Salary" minOccurs="0" maxOccurs="1" /> > <addr:Address minOccurs="1" maxOccurs="1"/> > </xsd:sequence> > </xsd:complexType> > .... > </xsd:schema> > > Here is the definition of the Address: > > <?xml version="1.0" encoding="UTF-8"?> > <xsd:schema targetNamespace="http://test.org/Address" > xmlns="http://test.org/address" > xmlns > xmlns > elementFormDefault="qualified" version="2.0"> > > <xsd:complexType name="addressType"> > <xsd:sequence> > <xsd:element minOccurs="1" maxOccurs="unbounded" > name="Line"><xsd:simpleType><xsd:restriction > base="xsd:string"/></xsd:simpleType></xsd:element> > <xsd:element minOccurs="1" maxOccurs="1" > name="City"><xsd:simpleType><xsd:restriction > base="xsd:string"/></xsd:simpleType></xsd:element> > <xsd:element minOccurs="1" maxOccurs="1" > name="State"><xsd:simpleType><xsd:restriction > base="xsd:string"/></xsd:simpleType></xsd:element> > <xsd:element minOccurs="1" maxOccurs="1" > name="zip"><xsd:simpleType><xsd:restriction > base="xsd:string"/></xsd:simpleType></xsd:element> > </xsd:sequence> > </xsd:complexType > > <xsd:element name="address" type="addressType"/> > </xsd:schema> > > This gives me an error message. > > Note, I have no problems bringing in a type from one schema into > another. That is, I created an addressType in the > http://test.org/Address > name space. I used that just fine to define an element in the > http://test.org/emp Schema. I am wondering if there is a way to bring > in an element itself from one schema into another. > > (I also tried writing using the ref attribute, but ref requires a > QName, not > a NCName. So I got a syntax error message if I was to write > <xsd:element ref="emp:Address") > > Dr. Laurence L. Leff, Ph.D. Associate Professor of Computer Science > Western Illinois University 1 University Circle Macomb IL 61455 309 367 > 0787 > |
|