Validate XML with Separated XSD

Hi,

I have received this .xsd file that has the following in it:

Code Snippet
<?

<?xmlversion="1.0"encoding="UTF-8"?>

<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"xmlns:t="urn:be-tn:MVNO:Logistics:ProcessKitOrder:0-02"targetNamespace="urn:be-tn:MVNO:Logistics:ProcessKitOrder:0-02">

<xs:annotation>

<xs:documentation>

<RegistryEntryName="ProcessKitOrder">

<Description>ProcessKitOrder</< FONT>Description>

</< FONT>RegistryEntry>

</< FONT>xs:documentation>

</< FONT>xs:annotation>

<xs:includeschemaLocation="../types/SchemaVersion_v0-01.xsd" />

<xs:includeschemaLocation="../types/MessageHeader_v0-02.xsd" />

<xs:includeschemaLocation="../types/OrderId_v0-01.xsd" />

<xs:includeschemaLocation="../types/OrderItems_v0-02.xsd" />

<xs:elementname="ProcessKitOrder">

<xs:complexType>

<xs:sequence>

<xs:elementname="SchemaVersion"type="t:SchemaVersionType"default="0.02" />

<xs:elementname="MessageHeader"type="t:MessageHeaderType" />

<xs:elementname="KitOrder">

<xs:complexType>

<xs:sequence>

<xs:elementname="OrderId"type="t:OrderIdType" />

<xs:elementname="OrderItems"type="t:OrderItemsType" />

</< FONT>xs:sequence>

</< FONT>xs:complexType>

</< FONT>xs:element>

</< FONT>xs:sequence>

</< FONT>xs:complexType>

</< FONT>xs:element>

</< FONT>xs:schema>

As you can see it has a lot of sub-xsd's but I think they aren't declared properly. For example the SchemaVersionType contains the following:

<?

Code Snippet

<?xmlversion="1.0"encoding="UTF-8"?>

<xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:annotation>

<xs:documentation>

<RegistryEntryName="SchemaVersion">

<Description>SchemaVersion</< FONT>Description>

</< FONT>RegistryEntry>

</< FONT>xs:documentation>

</< FONT>xs:annotation>

<xs:simpleTypename="SchemaVersionType">

<xs:restrictionbase="xs:string">

<xs:minLengthvalue="1"/>

<xs:maxLengthvalue="16"/>

</< FONT>xs:restriction>

</< FONT>xs:simpleType>

</< FONT>xs:schema>

Isn't it supposed to have it's own namespace ? Anyway, this might be all good but when I try to validate an XML file I get the following error ->

The element 'ProcessKitOrder' in namespace 'urn:be-tn:MVNO:LogisticsStick out tonguerocessKitOrder:0-02' has invalid child element 'SchemaVersion' in namespace 'urn:be-tn:MVNO:LogisticsStick out tonguerocessKitOrder:0-02'. List of possible elements expected: 'SchemaVersion'.

Does that make as much sense to you as it does to me?

I have tried to validate it in every single way. Currently I'm using the following:

Code Snippet

Dim xdAsNew XmlDocument

xd.LoadXml(xml)

xd.Schemas = GetSchema(xsd)

xd.Validate(AddressOf ValidationHandler)

xml = the xml in stringform and GetSchema(xsd) returns a shemaset containing the following schemas:

Code Snippet

ss.Add("urn:be-tn:MVNO:Logistics:ProcessKitOrder:0-02", base_dir &"xsd\docs\ProcessKitOrder_v0-02.xsd")

ss.Add("urn:be-tn:MVNO:Logistics:ProcessKitOrder:0-02:SchemaVersion", base_dir &"xsd\types\SchemaVersion_v0-01.xsd")

'..... etc I'm not showing the rest but it's similar.

What am I doing wrong? Or is there something wrong with the .xsd/xml ? The xml is the following by the way .. I ripped out the bits that aren't referenced above.

Code Snippet
<?xml version="1.0" encoding="UTF-8"?>
<
ProcessKitOrderxmlns="urn:be-tn:MVNO:Logistics:ProcessKitOrder:0-02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:be-tn:MVNO:Logistics:ProcessKitOrder:0-02 ../ProcessKitOrder_v0-02.xsd">
<SchemaVersion>0.02</SchemaVersion>
</ProcessKitOrder>

[18642 byte] By [SpoBo] at [2008-1-6]
# 1

I think the problem might be

xs:include puts that into the same target namespace

better to use

xs:import and specify the namespace....

See reference at

http://www.w3schools.com/schema/schema_elements_ref.asp

Viktor.Prehnal at 2007-10-2 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 2
Make sure those schemas that you include define the same targetNamespace as the main schema.
MartinHonnen at 2007-10-2 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 3

In your first schema, you need to specify elementFormDefault="qualified". This will qualify the local elements like SchemaVersion also in the targetNamespace of the schema. By default, local elements are not qualified.

<xsTongue Tiedchema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="urn:be-tn:MVNO:LogisticsStick out tonguerocessKitOrder:0-02" targetNamespace="urn:be-tn:MVNO:LogisticsStick out tonguerocessKitOrder:0-02" elementFormDefault="qualified">

Thanks,

Priya

# 4

I tried this and it appears to work ... sort of Surprise Now I have 2 errors .. each about the next Type in my RootNode. So, it appears this only worked for SchemaVersion. But that one is very simple and doesn't include any other types in itself. There is MessageHeaderType and OrderItemType next in the rootnode ... and they throw errors. I think because they include other types themselves. As an added bonus though these types need to be reused with different base .xsd's. Should I try placing elementFormDefault in every separate type that includes other types? Or should I place targetnamespaces in the types? But that won't work I guess since I need to reuse them with different .xsd's. Same for using import instead of include since the base namespace won't be the same every time. Thanks for the suggestions though peeps. Damn ... xml/xsd is hard Big Smile Thanks for the good start for the solution Priya. I'm going to experiment with placing it in different files and hope for the best Big Smile

edit: ok, so that didn't work. I also tried adding all my schemas under the same namespace during the validation .. same result. Could someone point me to an example where they do this? So, an .xsd containing multiple .xsd's that contain multiple ComplexTypes that themselves can contain other .xsd's with ComplexTypes in it... and make it all work together with different base .xsd's.

SpoBo at 2007-10-2 > top of Msdn Tech,.NET Development,XML and the .NET Framework...
# 5

To be sure that your question would not be loast you can file separate question instead of adding them to the same thread.

It would also help for if you bake minimum repro for your problem.

SergeyDubinets-MSFT at 2007-10-2 > top of Msdn Tech,.NET Development,XML and the .NET Framework...

.NET Development

Site Classified