471,306 Members | 850 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Partial XML Schema Validation?

I want to speed up the validation of some of my fairly large and
detailed XML files.

In particular there is a set of child elements and attributes that does
not to be validated after it has completed a certain point in the
system, but that will still be present in the file. At points later in
the system, when these files are read in, I do not want to validate
this section as it has already been validated much earlier, but still
need the data in the file for History.

The files are currently validated by an XSD (XML Schema) file that
specifies the valid types for every element and attribute. But what I'd
ideally like to do is change this schema for later applications so that
it will still accept these files, but ignore the child elements. So an
element entry in the schema like

<element name="foo" type="*" />

which would allow the "foo" element to be present in the XML file with
all its children and normal data, but for the XML Schema validation to
just see that it's there and skip it.

I've tried using the xs:any element for XSD as well as the above
scenario but to no avail.

Thank you for any and all comments!

Jul 23 '05 #1
9 4251
For further detail it is well to note that I am using this in a .NET/C#
environment

Jul 25 '05 #2
Hi,

Try just:

<element name="foo"/>

If no type is specified, it should allow anything (including mixed
content.)

Hope that helps,
Priscilla

----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Jul 26 '05 #3
This did not resolve the issue:
The error I receive upon doing this is:
---> System.Exception: Validate: Error validating xml file against
embedded schema. ---> System.InvalidOperationException: There is an
error in the XML document. ---> System.Exception: valHandler:
Validation failure: The 'http://lmco.com/DataCapture:W' element is not
declared.

The element that I adjusted per your instructions has child elements W
which in turn have Chrs and Chr elements (word, chars, char).
Apparently it needs to see these elements defined in the schema,
however I don't want them validated. I would just like it to see that
the 'foo' element is there, and ignore its contents and children and
move on.

Jul 26 '05 #4
br*****@bc3tech.net writes:
... what I'd
ideally like to do is change this schema for later applications so that
it will still accept these files, but ignore the child elements. So an
element entry in the schema like
...
which would allow the "foo" element to be present in the XML file with
all its children and normal data, but for the XML Schema validation to
just see that it's there and skip it.

I've tried using the xs:any element for XSD ... but to no avail.


The XSD 'any' element with processContents="skip" should do just what
you need. Can you show us a short example showing how you tried to
use it, and tell us what you expected it to do and what it did do?

--C. M. Sperberg-McQueen
World Wide Web Consortium
Jul 26 '05 #5
Schema before (takes too long during validation):

<xs:element name="Elt1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Child1"
minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="Child11"
minOccurs="0">
<xs:complexType>
<xs:attribute name="A"
form="unqualified" type="xs:nonNegativeInteger" />
<xs:attribute name="C"
form="unqualified" type="xs:nonNegativeInteger" />
<xs:attribute name="D"
form="unqualified" type="xs:nonNegativeInteger" />
</xs:complexType>
</xs:element>
<xs:element name="Child12"
minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element
name="Child121" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element
name="Child1211" minOccurs="0">

<xs:complexType>

<xs:sequence>

<xs:element name="Child12111" minOccurs="0" maxOccurs="unbounded">

<xs:complexType>

<xs:attribute name="C" form="unqualified" type="xs:nonNegativeInteger"
/>

<xs:attribute name="V" form="unqualified" type="xs:string" />

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>
</xs:element>
<xs:element
name="Child1212" minOccurs="0">

<xs:complexType>

<xs:attribute name="x" form="unqualified" type="xs:nonNegativeInteger"
/>

<xs:attribute name="y" form="unqualified" type="xs:nonNegativeInteger"
/>

<xs:attribute name="w" form="unqualified" type="xs:nonNegativeInteger"
/>

<xs:attribute name="h" form="unqualified" type="xs:nonNegativeInteger"
/>

</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="Ct"
form="unqualified" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Attempted Schema

<xs:element name="Elt1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip" />
</xs:sequence>
</xs:complexType>
</xs:element>
Error received:

---> System.Exception: Validate: Error validating xml file against
embedded schema. ---> System.InvalidOperationException: There is an
error in the XML document. ---> System.Exception: valHandler:
Validation failure: The element 'Elt1' has incomplete content.

Thanks for your responses!

Jul 27 '05 #6
Hi,

You need to put minOccurs="0" maxOccurs="unbounded" on xs:any if you
want to allow any number of children. Also, if you want to allow Elt1
to have character data content, you should put mixed="true" on the
xs:complexType element.

But really, <xs:element name="Elt1"/> should work. It should not require
that the child element be declared. What processor are you using?

Hope that helps,
Priscilla
----------------------------------
Priscilla Walmsley
Author, Definitive XML Schema
http://www.datypic.com
----------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Jul 27 '05 #7
"BC3Tech" <br*****@bc3tech.net> writes:
Schema before (takes too long during validation):

<xs:element name="Elt1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Child1" minOccurs="0" maxOccurs="unbounded">
...
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Attempted Schema

<xs:element name="Elt1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip" />
</xs:sequence>
</xs:complexType>
</xs:element>
Why does the 'Attempted Schema' allow only one child of
Elt1? The base schema allows an unbounded number; I'd
expect the xs:any element to have maxOccurs="unbounded".

And on the other pole of the spectrum, why does it require one child,
given that in the original schema Elt1 may be childless?
I'd expect minOccurs="0".
Error received:

---> System.Exception: Validate: Error validating xml file against
embedded schema. ---> System.InvalidOperationException: There is an
error in the XML document. ---> System.Exception: valHandler:
Validation failure: The element 'Elt1' has incomplete content.


Looks like your test example was a childless Elt1.

--C. M. Sperberg-McQueen
World Wide Web Consortium
Jul 27 '05 #8
The processor I'm using is that of the .NET Framework 1.1 w/ sp1. I've
found that they plan to have some Partial Validation methods in the
next version of the Framework (v2, due out sept), but don't have until
then to wait, and we don't plan to integrate that into the project when
it does come out.

I just tried your solution to add the Mixed and min/max to the any
element and it worked!

I was confused when the /> element didn't work either, but what can ya
do.

Jul 27 '05 #9
Yes, a childless Elt1 was exactly what I wanted to be able to have and
have it skip over, which could then be inferred that I could have an
Elt1 that had children and those would also get skipped which is
exactly what I want.

However the solution was found by Priscilla and I greatly appreciate
both of your responses. Hopefully this will afford us quite a bit of
performance gain in our system since these are used greatly.

Thanks again!

Jul 27 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by wumingshi | last post: by
1 post views Thread by Dan Bass | last post: by
2 posts views Thread by Ali | last post: by
1 post views Thread by billa1972 | last post: by
reply views Thread by Matt | last post: by
reply views Thread by Mark Parter | last post: by

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.