complexType in Xml Schema

P

Peter Theill

Hi,

I'm trying to build an element which will allow Xml such as:

<location type="home">
<AddressLine1>xyz</AddressLine1>
</location>

<location type="work url">
<Url>http://xyz/</Url>
</location>

The content of the location node should allow anything so I'm trying to use
xsd:anyType. I've defined this complex type:

<xsd:complexType name="location">
<xsd:complexContent>
<xsd:extension base="xsd:anyType">
<xsd:attribute name="type" type="xsd:string" use="required" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

However my schema validator (XmlSchemaSet class of the .NET 2.0 frameworK)
can't validate and tells me "The derived type and the base type must have
the same content type.". What do I miss?
 
M

Martin Honnen

Peter Theill wrote:

I'm trying to build an element which will allow Xml such as:

<location type="home">
<AddressLine1>xyz</AddressLine1>
</location>

<location type="work url">
<Url>http://xyz/</Url>
</location>

The content of the location node should allow anything so I'm trying to use
xsd:anyType. I've defined this complex type:

<xsd:complexType name="location">
<xsd:complexContent>
<xsd:extension base="xsd:anyType">
<xsd:attribute name="type" type="xsd:string" use="required" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

However my schema validator (XmlSchemaSet class of the .NET 2.0 frameworK)
can't validate and tells me "The derived type and the base type must have
the same content type.". What do I miss?

Why can't you use
<xsd:complexType>
<xsd:sequence>
<xsd:any />
<xsd:sequence>
<xsd:attribute ... />
</xsd:complexType>
that is the proper way I think, you can then also decide whether to have
precessContents="lax" or processContents="skip" on the xsd:any element.
 
P

Peter Theill

that is the proper way I think, you can then also decide whether to have
precessContents="lax" or processContents="skip" on the xsd:any element.

Thanks Martin, that was exactly what I was looking for. Now my validator is
able to process the file just fine.

Rgd,
Peter Theill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top