Add

   elementFormDefault="qualified"

to the xsd:schema element in schema a to get the behavior you were
expecting.  This menas that elements declared within a complexType
definition are in the target namespace of the schema.  This attribute
has the default value "unqualified", meaning such elements are in no
namespace.  Elements declared at top level (children of the <schema>
element) are always in the target namespace of the schema.

Jeff

On 10/19/06, Sean McCauliff <[EMAIL PROTECTED]> wrote:
I have a schema file where I define two complex types and one of the
complex types defines an element with the type of the other complex
type.  When I write an instance file the enclosed element is in an
empty namespace instead of being defined in the name space of the type
or of the enclosing element.  See instance_a.xml and schema_a.xsd
below.

schema_a.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
           targetNamespace="http://eslug.net";
           xmlns="http://eslug.net";
>
  <xsd:complexType name="bType">
     <xsd:attribute name="anotherattr" type="xsd:string" use="required" />
   </xsd:complexType>

  <xsd:complexType name="aType">
     <xsd:sequence>
       <xsd:element name="b" type="bType" minOccurs="0" maxOccurs="unbounded" />
     </xsd:sequence>
     <xsd:attribute name="someattr" type="xsd:string" />
  </xsd:complexType>

  <xsd:element name="a" type="aType" />

</xsd:schema>

instance_a.xml
<blah:a xmlns:blah="http://eslug.net"; someattr="blah"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation=
            "http://eslug.net file:schema_a.xsd"
>
  <!-- element b, below does not need to have the "blah:" ns prefix
inorder to be valid.
        It is in the empty namespace.
   -->
  <b anotherattr="blah" />
</blah:a>


If I change the schema so that the bType is defined as an element
instead.  Then "b" is not in the http://eslug.net namespace.

schema_b.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
           targetNamespace="http://eslug.net";
           xmlns="http://eslug.net";
>
  <xsd:element name="b">
    <xsd:complexType >
     <xsd:attribute name="anotherattr" type="xsd:string" use="required" />
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="a" >
    <xsd:complexType >
       <xsd:sequence>
         <xsd:element ref="b" maxOccurs="unbounded" />
       </xsd:sequence>
       <xsd:attribute name="someattr" type="xsd:string" />
    </xsd:complexType>
  </xsd:element>


</xsd:schema>

instance_b.xml
<blah:a xmlns:blah="http://eslug.net"; someattr="blah"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
        xsi:schemaLocation=
            "http://eslug.net file:schema_b.xsd"
>
  <!-- b is now in the correct namespace. -->
  <blah:b anotherattr="blah" />
</blah:a>

I would rather use schema a, but elements of "bType" only seem to show
up in the empty namespace forcing me to use schema_b.

Is this a bug or there some misunderstanding with how namespaces are
assigned to compexTypes in xml schema?

Thanks,
-Sean

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to