Geeks With Blogs
Nigel Parker BizTalk 2004 Developer - Auckland, New Zealand,

I was reading this article http://devresource.hp.com/drc/slide_presentations/schemaWSDL/index.jsp and it got me thinking about how I have been designing schemas in BizTalk… Yes I know I can already hear your groans about the “BizTalk XSD schema editor”.

Well contrary to popular believe you don’t need to use monolithic structures in BizTalk schema design. From the BizTalk Server 2004 book… p78 – Building Message Specifications – Imports – “Only schemas that are part of the current project may be imported”… I thought I’d take on building the xsd structure described in the above article using Visual Studio armed with only the BizTalk Editor and the XML Schema Editor. TIP For those that don’t know you can still access the XML Schema Editor after BizTalk is installed by right-clicking on the XSD in Visual Studio and selecting Open With… see below.

First I built the Common Types schema. I did this using the XML Schema Editor initially and then opening it in the BizTalk Editor afterwards… the resulting schema is shown below.

CommonTypes.xsd

 <?xml version="1.0" encoding="utf16"?>

<schema xmlns:qc="http://XMLImport.CommonTypes/supplier/quoteCommon" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://XMLImport.CommonTypes/supplier/quoteCommon" xmlns="http://www.w3.org/2001/XMLSchema">

<complexType name="OwnerDetails">

<attribute name="CustId" type="string" use="required"/>

<attribute name="CustName" type="string" use="required"/>

<attribute name="CustEmail" type="string" use="required"/>

</complexType>

<complexType name="PartItemType">

<attribute name="SKU" type="string" use="required"/>

<attribute name="Descr" type="string" use="required"/>

<attribute name="Qty" type="int" use="required"/>

<attribute name="QuotedPrice" type="float" use="optional"/>

</complexType>

<complexType name="PartListType">

<sequence>

<element maxOccurs="unbounded" name="PartListType" type="qc:PartItemType"/>

</sequence>

</complexType>

</schema>

I then built the Quote Request schema. For this schema I followed the same method as the above schema but I added the import using Import function in the BizTalk Editor (Open the xsd in the BizTalk editor, click on and click on the ellipse in the Import field of the advanced properties, select the commontypes.xsd; I also changed the namespace to “common”).

QuoteRequest.xsd

<?xml version="1.0" encoding="utf16" ?>

 <schema xmlns:supReq="http://XMLImport.CommonTypes/supplier/types" xmlns:common="http://XMLImport.CommonTypes/supplier/quoteCommon" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://XMLImport.CommonTypes/supplier/types" xmlns="http://www.w3.org/2001/XMLSchema">

  <import schemaLocation=".\commontypes.xsd" namespace="http://XMLImport.CommonTypes/supplier/quoteCommon" />

 <annotation>

 <appinfo>

 <b:references>

  <b:reference targetNamespace="http://XMLImport.CommonTypes/supplier/quoteCommon" />

  </b:references>

  </appinfo>

  </annotation>

 <complexType name="QuoteRequestType">

 <sequence>

  <element name="CustomerDetails" type="common:OwnerDetails" />

  <element name="PartList" type="common:PartListType" />

  </sequence>

  </complexType>

  <element name="QuoteRequest" type="supReq:QuoteRequestType" />

  </schema>

At this point I thought I’d take the example one step further what if I wanted to create a new schema that referenced “Both” of the previous two schemas… bearing in mind that the second schema already referenced the first set of complex types. Is this possible using the BizTalk Editor? It turns out is but there is a trick to it.

I followed the process of creating a new schema and opening it in the BizTalk Editor.

The trick here is the order that you apply the import statements!

If you attempt to import QuoteRequest.xsd and then import CommonTypes.xsd you get the following error:

 

This is because CommonTypes.xsd is already imported by QuoteRequest.xsd and the reference to common types has already been partially added but in an unusable way.

You need to import CommonTypes.xsd and then import QuoteRequest.xsd this way the BizTalk Editor is happy and you can proceed to use those imported types in your new schema.

CustomerQuoteRequests.xsd

<?xml version="1.0" encoding="utf16" ?>

 <schema xmlns:supReq="http://XMLImport.CommonTypes/supplier/quoteCommon" xmlns:custSupReq="http://XMLImport.CustomerQuoteRequests" xmlns:common="http://XMLImport.CommonTypes/supplier/types" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://XMLImport.CustomerQuoteRequests" xmlns="http://www.w3.org/2001/XMLSchema">

  <import schemaLocation=".\commontypes.xsd" namespace="http://XMLImport.CommonTypes/supplier/quoteCommon" />

  <import schemaLocation=".\quoterequest.xsd" namespace="http://XMLImport.CommonTypes/supplier/types" />  <annotation>

 <appinfo>

 <b:references>

  <b:reference targetNamespace="http://XMLImport.CommonTypes/supplier/quoteCommon" />

  <b:reference targetNamespace="http://XMLImport.CommonTypes/supplier/types" />

  </b:references>

  </appinfo>

  </annotation>

 <element name="CustomerQuoteRequests">

 <complexType>

 <sequence>

  <element name="CustomerDetails" type="supReq:OwnerDetails" />

  <element minOccurs="0" maxOccurs="unbounded" name="QuoteRequest" type="common:QuoteRequestType" />

  </sequence>

  </complexType>

  </element>

  </schema> 

In summary to steal a quote from the above article:

1.       Use a modular schema design

o        Maximizes reuse

o        Simplifies code generation

2.       Use namespaces effectively

o        Simplifies external references

o        Can enforce version control

3.       Leverage import features

o        Provides great reusability

o        Use tools appropriately

4.       Focus on interoperability

o        All types aren't supported

o        Add testing methodology

In the end . . .

the proper use of XML Schemas can greatly improve:

  • reusability
  • flexibility
  • maintainability
  • portability
Posted on Friday, February 11, 2005 10:13 AM BizTalk Tips & Tricks | Back to top


Comments on this post: Using XML schemas effectively within the BizTalk 2004 XSD Schema Editor

# re: Using XML schemas effectively within the BizTalk 2004 XSD Schema Editor
Requesting Gravatar...
Hi Nigel,
I have been trying to accomplish this very same task in a BizTalk 2004 project I have as you describe here. I keep getting what looks like a low-level error when I attempt to validate my schemas that does not give much clue as to the real problem:
"Custom component invocation failed. Object reference not set to an instance of an object."

I tried validating the schemas you posted (CommonTypes.xsd, QuoteRequest.xsd and CustomerQuoteRequests.xsd) verbatim as you have them. After creating the schemas using the XML Schema Editor, I was able to successfully validate CommonTypes.xsd and QuoteRequest.xsd within BizTalk. However when I try to validate CustomerQuoteRequests.xsd, I receive the identical error as I wrote above. When I try to open CustomerQuoteRequests.xsd in the BizTalk Editor I get a message box with the error "Failed to load schema."

Were you able to validate these schemas in BizTalk? Is there a hotfix or service pack that I'm missing? I have already installed BTS2004SP1, and I am running Windows 2003.
thank you,
Margaret
Left by Margaret on Mar 02, 2005 10:02 AM

# re: Using XML schemas effectively within the BizTalk 2004 XSD Schema Editor
Requesting Gravatar...
Margaret responded to this post via email; her response is here:

"The GDR update was exactly what I needed-your example schemas and my project schemas all validate successfully now. Thanks so much for your speedy reply.

-Margaret"
Left by Nigel Parker on Mar 04, 2005 8:53 AM

# re: Using XML schemas effectively within the BizTalk 2004 XSD Schema Editor
Requesting Gravatar...
Hi niegel, This post is very useful (The example too - works). I have a question. I am trying to Work with Xcbl 4.0 (www.xcbl.org) and BTS 2004, but i can`t start yet because i can`t compile the xcbl schemas (core.xsd) for my project. this schema is a valid schema for biztalk and include many other mini schemas, so i must including in the project too (for core.xsd validation), but the other are not valid schemas for Biztalk, so i edited for be valid in Biztalk (adding the imports missing), after do that, when i open the core schema showme the error that you describe "already has been declared". I folow the procedure that you say for that error but not help. Can you tell me something to help me?
thanks in advance.
Left by Hector Silva on Aug 19, 2005 12:18 AM

# re: Using XML schemas effectively within the BizTalk 2004 XSD Schema Editor
Requesting Gravatar...
Hi Niegel,

I was reading your post and maybe you can help me with a problem that is related to the example you described.

In a project I'm currently working on we use XML type definitions and inheritance. So say for example that in the schema's you created the PartItemType is used as an abstract base-class and both the CarPartItemType and AirplanePartItemType inherit from it. In the message map tool this will be displayed with a ‘<Equivalent>’ tag. How can I force the tool to construct a message containing the correct structure for either one of them (preferably the one I choose).

Thanks in advance

Left by Ferdinand on Feb 16, 2006 8:26 PM

Your comment:
 (will show your gravatar)


Copyright © Nigel Parker | Powered by: GeeksWithBlogs.net