469,927 Members | 1,403 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Validating inherited types XML Schema

I'm trying to write a schema that allows me to substitute entensions
for a base type. The schema (included below) defines a StepType and
an AnnouncementStepType that is an extension of the base type.

Unfortunately, my XML example fails validation. When I omit PromptID,
the Visual Studio Taskpane reads: "The element 'urn:Test:Step' has
incomplete content. Expected 'urn:Test:PromptID'. An error occurred at
, (11, 7).". If I add in <PromptID></PromptID> into the file, the
validation fails again, but this time with the message: "The active
schema does not support the element 'PromptID'." I've attempted to
add in <lh:PromptID /> with the same result.

Does anyone have any ideas on how I can get this to work in Visual
Studio? I've tried programmatically validating the document and that
fails horribly claiming that all elements are invalid.

Schema
-------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="urn:Test" xmlns:lh="urn:Test"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="StepType" abstract="true">
<xs:sequence>
<xs:element name="Type" />
<xs:element name="AssemblyLocation" />
<xs:element name="Version" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="AnnounceStepType">
<xs:complexContent>
<xs:extension base="lh:StepType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="PromptID"
type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Module">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Name"
type="xs:string" />
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="Step"
type="lh:StepType" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML Sample
-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Module xmlns:lh="urn:Test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Test">
<Name>Test Module</Name>
<Step xsi:type="AnnounceStepType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Type>
</Type>
<AssemblyLocation>
</AssemblyLocation>
<Version>
</Version>
</Step>
</Module>
Nov 12 '05 #1
2 1405
Dan,

The sample XML you posted validates fine for me in Visual Studio.

Did you add both, schema and document, to the Visual Studio project that you
have open?

--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

"Dan Shookowsky" <sh*****@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I'm trying to write a schema that allows me to substitute entensions
for a base type. The schema (included below) defines a StepType and
an AnnouncementStepType that is an extension of the base type.

Unfortunately, my XML example fails validation. When I omit PromptID,
the Visual Studio Taskpane reads: "The element 'urn:Test:Step' has
incomplete content. Expected 'urn:Test:PromptID'. An error occurred at
, (11, 7).". If I add in <PromptID></PromptID> into the file, the
validation fails again, but this time with the message: "The active
schema does not support the element 'PromptID'." I've attempted to
add in <lh:PromptID /> with the same result.

Does anyone have any ideas on how I can get this to work in Visual
Studio? I've tried programmatically validating the document and that
fails horribly claiming that all elements are invalid.

Schema
-------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="urn:Test" xmlns:lh="urn:Test"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="StepType" abstract="true">
<xs:sequence>
<xs:element name="Type" />
<xs:element name="AssemblyLocation" />
<xs:element name="Version" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="AnnounceStepType">
<xs:complexContent>
<xs:extension base="lh:StepType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="PromptID"
type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Module">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="Name"
type="xs:string" />
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="Step"
type="lh:StepType" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML Sample
-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<Module xmlns:lh="urn:Test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:Test">
<Name>Test Module</Name>
<Step xsi:type="AnnounceStepType"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Type>
</Type>
<AssemblyLocation>
</AssemblyLocation>
<Version>
</Version>
</Step>
</Module>

Nov 12 '05 #2
What version of Visual Studio.NET are you using? I'm confused because
when I choose "Validate XML Data" from the menu, the status text at the
bottom of the screen reads: "No Validation Errors were found" while the
PromptID tag is underlined in red and the task pane is saying that the
active schema doesn't recognize the element.

Both files are members of the same project.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Iain | last post: by
2 posts views Thread by Joris Janssens | last post: by
1 post views Thread by Craig Beuker | last post: by
reply views Thread by Patrick Brunmayr | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.