all groups > dotnet xml > february 2005 >
You're in the

dotnet xml

group:

XML parsing error with schema



XML parsing error with schema Edward Diener
2/25/2005 11:19:09 AM
dotnet xml: I have a simple XML file:

<?xml version='1.0'?>
<Employee xmlns='urn:MyEmployee-schema'>
<Name>
<First>
Edward
</First>
<Last>
Diener
</Last>
</Name>
</Employee>

and a schema to use to validate it:

<?xml version='1.0'?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'
targetNamespace='urn:MyEmployee-schema'>
<xs:element name='Employee'>
<xs:complexType>
<xs:sequence>
<xs:element name='Name'>
<xs:complexType>
<xs:sequence>
<xs:element name='First' type='xs:string' />
<xs:element name='Last' type='xs:string' />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

When I try to validate I get:

"Error at (3,4): The element 'urn:MyEmployee-schema:Employee' has invalid
child element 'urn:MyEmployee-schema:Name'. Expected 'Name'. An error
occurred at , (3, 4)."

I do not understand this error. Why is 'Name' expected when I have set the
targetNamespace in my schema to 'urn:MyEmployee-schema' ?

Re: XML parsing error with schema Edward Diener
2/25/2005 1:09:45 PM
[quoted text, click to view]

Thanks ! I naturally assumed that by specifying a targetNamespace that all
attributes and elements would be qualified. Odd that that is not the
default, but at least I now know.

Re: XML parsing error with schema Martin Honnen
2/25/2005 6:53:29 PM


[quoted text, click to view]

Add
elementFormDefault="qualified" attributeFormDefault="unqualified"
as attributes to the <xs:schema> element if you have targetNamespace and
want all elements to be in that targetNamespace.



--

Martin Honnen
AddThis Social Bookmark Button