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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top