Schema for XML with elements that have namespce and elements without
Hi
How do I create a schema for an XML that has elements that have namespace and elements without a namespace?
For example:
<metadata>
<ns:record>
<fields>...</fields>
</ns:record>
</metadata>
The schema that XMLSPY creates is:
<!--W3C Schema generated by XMLSpy v2006 sp2 U (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="fields">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="..."/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="metadata">
<xs:complexType>
<xs:sequence>
<xs:element name="record" type="recordType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="recordType">
<xs:sequence>
<xs:element ref="fields"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
but I can't use namespaces with that schema.
?
[1237 byte] By [
chilcoma] at [2007-10-2 11:47:42]

Just remember if u don't provide namespace it will use the default.
If u provide it explicitely then it will use whatever u have provided.
Here is XML File:
<?xml version="1.0" encoding="UTF-8"?>
<Customer xmlns:cust="http://www.xyz.com">
<cust:Name xmlns:name="http://www.xyz.com/name">yogesh</cust:Name>
<Add>Pune</Add>
<bal:Balance xmlns:bal="http://www.xyx.com/bal">1000</bal:Balance>
</Customer>
And the Schema foe that is :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="Add" type="xs:string"/>
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="cust:Name" ref="cust:Name"/>
<xs:element name="Add" ref="Add"/>
<xs:element name="bal:Balance" ref="bal:Balance"/>
</xs:sequence>
<xs:attribute name="xmlns:cust" type="xs:anyURI" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="bal:Balance">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:short">
<xs:attribute name="xmlns:bal" type="xs:anyURI" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="cust:Name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="xmlns:name" type="xs:anyURI" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
Hope this will help u.
.........yogesh
Hi yogesh
Thanks for your suggestion. I tryed pasting your suggestion in XML spy and validating it. I get an error message:
"Schema error - name='cust:Name' can't have a namespace prefix. Please remove prefix or use ref= instead!"
I get the same message when using microsoft schema validation tool at:
http://apps.gotdotnet.com/xmltools/xsdvalidator/default.aspx
Am i missing something?
Thanks again
David