Can I create an xml that specifies element from 2 nested xsd's without using a prefixes?

Posted by TweeZz on Stack Overflow See other posts from Stack Overflow or by TweeZz
Published on 2012-06-29T08:28:02Z Indexed on 2012/06/29 9:16 UTC
Read the original article Hit count: 199

Filed under:
|
|
|

I have 2 xsd's which are nested:

DefaultSchema.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="DefaultSchema"
    targetNamespace="http://myNamespace.com/DefaultSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://myNamespace.com/DefaultSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:complexType name="ZForm">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Part" minOccurs="0" maxOccurs="unbounded" type="Part"/>
    </xs:sequence>
    <xs:attribute name="Title" use="required" type="xs:string"/>
    <xs:attribute name="Version" type="xs:int"/>
  </xs:complexType>

  <xs:complexType name="Part">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:element name="Label" type="Label" minOccurs="0"></xs:element>
    </xs:sequence>
    <xs:attribute name="Title" use="required" type="xs:string"/>
  </xs:complexType>
  <xs:complexType name="Label">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Title" type="xs:string"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:schema>

ExportSchema.xsd: (this one kinda wraps 1 more element (ZForms) around the main element (ZForm) of the DefaultSchema)

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ExportSchema"
    targetNamespace="http://myNamespace.com/ExportSchema.xsd"
    elementFormDefault="qualified"
    xmlns="http://myNamespace.com/DefaultSchema.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:es="http://myNamespace.com/ExportSchema.xsd"
>
  <xs:import namespace="http://myNamespace.com/DefaultSchema.xsd" schemaLocation="DefaultSchema.xsd"/>

  <xs:element name="ZForms" type="es:ZFormType"></xs:element>

  <xs:complexType name="ZFormType">
    <xs:sequence>
      <xs:element name="ZForm" type="ZForm" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

And then finally I have a generated xml:

<?xml version="1.0" encoding="utf-8"?>
<ZForms xmlns="http://myNamespace.com/ExportSchema.xsd">
  <ZForm Version="1" Title="FormTitle">
    <Part Title="PartTitle" >
      <Label Title="LabelTitle" />
    </Part>
  </ZForm>
</ZForms>

Visual studio complains it doesn't know what 'Part' is.
I was hoping I do not need to use xml namespace prefixes (..) to make this xml validate, since ExportSchema.xsd has a reference to the DefaultSChema.xsd.

Is there any way to make that xml structure valid without explicitly specifying the DefaultSchema.xsd? Or is this a no go?

© Stack Overflow or respective owner

Related posts about Xml

Related posts about visual-studio