Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : XmlValidatingReader too sensitive?


Adam Smith
6/11/2004 6:55:26 AM
XmlValidatingReader too sensitive?

I have the following schemas (simplified) and xml file which validate
fine in xmlspy, but blow up in xmlvalidatingreader with:

'The 'Hierarchy' element is not declared. An error occurred'.

Any help appreciated.

To give a brief explanation of what I'm trying to do, the schema 1 is a
schema that is coming from a third party. The schema 2 is a wrapper
around that document.

The problem comes into light when a document based upon schema 1 has an
element outside of any namespace. Even though I qualify the tag, as in
<Hierarchy xmlns="">, xmlvalidatingreader chokes on it. xmlspy is fine.

schema 1 (3rd party)
--------
<xsd:schema targetNamespace="http://ns.hr-xml.org/SIDES/SIDES-1_0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://ns.hr-xml.org/SIDES/SIDES-1_0"
elementFormDefault="qualified">
<xsd:complexType name="StaffingOrderType">
<xsd:element name="samplefield" type="xsd:string" />
</xsd:complexType>
<xsd:element name="StaffingOrder" type="StaffingOrderType" />
</xsd:schema>

schema 2 (our wrapper hosted on our side)
--------
<xs:schema targetNamespace="http://ns.hr-xml.org/SIDES/SIDES-1_0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://ns.hr-xml.org/SIDES/SIDES-1_0"
elementFormDefault="qualified" id="MultipleHRXML">
<xs:include schemaLocation="StaffingOrder-1_0.xsd" />
<xs:complexType name="MultipleHRXMLSidesType">
<xs:element name="StaffingOrder" type="StaffingOrderType" />
</xs:complexType>

<xs:element name="MultipleHRXML-SIDES" type="MultipleHRXMLSidesType" />
</xs:schema>

example doc based on schema 2
-----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<MultipleHRXML-SIDES xmlns="http://ns.hr-xml.org/SIDES/SIDES-1_0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.hr-xml.org/SIDES/SIDES-1_0
http://localhost/HRXML/SIDES/SIDES-1_0/MultipleHRXML-SIDES-1_0.xsd">

<StaffingOrder xsi:schemaLocation="http://ns.hr-xml.org/SIDES/SIDES-1_0
http://ns.hr-xml.org/SIDES/SIDES-1_0/StaffingOrder-1_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://ns.hr-xml.org/SIDES/SIDES-1_0">
<samplefield>test</samplefield>

<!-- *****NOTE BELOW CAUSES THE PROBLEM******-->

<Hierarchy xmlns="">somevalue</Hierarchy>
</StaffingOrder>
</MultipleHRXML-SIDES>

---Thanks in advance
Adam Smith

*** Sent via Devdex http://www.devdex.com ***
Dare Obasanjo [MSFT]
6/14/2004 1:47:31 PM
Your XML schema is for elements from the
"http://ns.hr-xml.org/SIDES/SIDES-1_0" namespace. Your element is explicitly
set to having no namespace using xmlns="" and you have elementFormDefault
set to qualifued meaning that the element should be in the target namespace
of the schema.

Read the article at
http://msdn.microsoft.com/library/en-us/dnexxml/html/xml08192002.asp for
more information on this.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]

Priya Lakshminarayanan [MSFT]
6/14/2004 2:02:05 PM
The "StaffingOrderType" declares only one element SampleField. Once a schema
is found for the xml, XmlValidatingReader will validate according to that
schema and will not skip elements that do not belong to the targetNamespace.
XmlSPY has a bug here as the content model of StaffingOrderType does not
allow anything else other than the samplefield element.

Hence, undeclaring the default namespace in <Hierarchy
xmlns="">somevalue</Hierarchy> will not make the validating reader skip
validation for this element.

If you need elements in the empty namespace to be allowed as children of the
"StaffingOrder" element, then you need to define StaffingOrderType as open
content model using xs:any:
<xsd:complexType name="StaffingOrderType">
<xsd:sequence>
<xsd:element name="samplefield" type="xsd:string" />
<xsd:any namespace="##local" processContents="lax"/> --> ##local
allows only elements with no namespace
</xsd:sequence>
</xsd:complexType>

Thanks,
Priya

[quoted text, click to view]

AddThis Social Bookmark Button