473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

XmlValidatingReader too sensitive?

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 ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
4 1561
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...ml08192002.asp for
more information on this.

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

"Adam Smith" <ad*********@hotmail.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl...
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 ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #2
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...ml08192002.asp for
more information on this.

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

"Adam Smith" <ad*********@hotmail.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl...
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 ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #3
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

"Adam Smith" <ad*********@hotmail.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl...
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 ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #4
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

"Adam Smith" <ad*********@hotmail.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl...
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 ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alejandro Calbazana | last post by:
Hello, Should the XmlValidatingReader validating xml against an xsd serially (e.g. - does the XML have to be in the correct position in order for a document to be valid)? For example, I am...
18
by: Vlad | last post by:
I have the following code: I have a local copy of the DTD that I need to validate incoming XML documents against. The XML document has the <!DOCTYPE myname SYSTEM "myfile.dtd"> define. When the...
0
by: Adam Smith | last post by:
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...
4
by: Jesse Elve | last post by:
I am using an XmlValidatingReader which uses an XSD for xml validation. The code has been performing reliably for months. Yesterday it failed for the first time with the following exception: ...
9
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
1
by: Bernhard Felkel | last post by:
I have troubles validating XML files with key/keyref constraints. Here´s my schema: <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
1
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST> xml file 2
12
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.