Problem
If you try to use code generated from more than one schema in the same project, then you may get filename clashes.
or
If you generate code from 2 schemas which share a common set of XSD files, then you may get duplicate classes to represent the same elements.
Sample Schemas
Common.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="AddressType"> <xs:sequence> <xs:element name="House" type="xs:string"/> <xs:element name="Street" type="xs:string"/> <xs:element name="City" type="xs:string"/> <xs:element name="County" type="xs:string"/> <xs:element name="PostCode" type="xs:string"/> <xs:element name="Country" type="CountryCodes"/> </xs:sequence> </xs:complexType> <xs:simpleType name="CountryCodes"> <xs:restriction base="xs:string"> <xs:enumeration value="UK"/> <xs:enumeration value="US"/> <xs:enumeration value="France"/> <xs:enumeration value="Germany"/> </xs:restriction> </xs:simpleType> </xs:schema>
Person.xsd<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:include schemaLocation="Common.xsd"/> <xs:element name="Person"> <xs:complexType> <xs:sequence> <xs:element name="Name"/> <xs:element name="Address" type="AddressType"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Invoice.xsd<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:include schemaLocation="Common.xsd"/> <xs:element name="Invoice"> <xs:complexType> <xs:sequence> <xs:element name="InvoiceNo" type="xs:unsignedLong"/> <xs:element name="InvoiceAmount" type="xs:double"/> <xs:element name="InvoiceAddress" type="AddressType"/> <xs:element name="TaxRegion" type="CountryCodes"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Resolution
When your working with a single schema, then everything is straight forward, but if your using code from 2 or more schemas then you can run into problems. In C++ you can get name clashes, and in other languages you can get more than one class representing a single instance of an element (one from each generation).
There are 2 ways to solve the problem.
Create a Super Schema
This is the approach we recommend. It has the advantage of minimizing the amount of code generated, without the need to change the schema's or deal with re-mapping names.
In essence its very simple, you create an additional schema document that just included's the other schemas you are working with.
SuperSchema.xsd
If the external schema has the same targetNamespace (as in our example above) use include:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:include schemaLocation="Invoice.xsd"/> <xs:include schemaLocation="Person.xsd"/> </xs:schema>
Alternatively, if the external schema has a different targetNamespace use import:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:import namespace="http://www.example.org/invoice" schemaLocation="Invoice.xsd"/> <xs:import namespace="http://www.example.org/person" schemaLocation="Person.xsd"/> </xs:schema>
You now generate your code form this schema, and it will pull in all of the child entries.
Note:
The wizard uses MSXML internally to parser the XSD schema. MSXML4 can have problems parsing files with includes, so if you experience problems generating the code, then it is recommended that you install MSXML 6 - (See Problems with Code Generation and MSXML).
Remapping names
The other approach is to re-map any names that clash when you attempt to compile the code. This is not ideal, as it can mean some manual intervention, and can also lead to code duplication.
You can use the name re-mapping tool to accomplish this
Notes
Description | Value |
---|---|
Article Created | 8/2/2006 |
Applies to | Liquid XML 2005 and greater |
Also See | Name Re-mapping |
MSXML 6 |