Partial XML Schema Validation?

B

brandon

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!
 
B

BC3Tech

For further detail it is well to note that I am using this in a .NET/C#
environment
 
P

Priscilla Walmsley

Hi,

Try just:

<element name="foo"/>

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

Hope that helps,
Priscilla
 
B

BC3Tech

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.
 
C

C. M. Sperberg-McQueen

... 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
 
B

BC3Tech

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!
 
P

Priscilla Walmsley

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
 
C

C. M. Sperberg-McQueen

BC3Tech said:
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
 
B

BC3Tech

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.
 
B

BC3Tech

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top