Validate subsets of XML document using different schema?

L

Lord0

I *think* I need to be able to validate subsets of an XML document
using different schema. The functionality I'm trying to implement is
this.

a) External suppliers produce an XML document containing multiple User
records. The external supplier validates this entire document using
schema 1. This document is then uploaded to our system.

b) Our system then checks that the supplied document "looks okay",
minimally, using Schema 2. Schema 2 just looks for a <users> element
containing one or more <user> elements, each of which which may contain
"anything". If the document fails this validation the external supplier
receives a message like "This does not look like a valid User records
document" and processing stops.

c) Assuming the record passed b) above then each individual <user>
record is extracted and validated using Schema 3. Allowing us to say
something like "User record 1 was valid, User record 2 was invalid:
Name missing" etc.

## Sample XML

1,2 <users>
1,2,3 <user>
1 ,3 <name/>
1 ,3 <phone/>
1 ,3 <email/>
1,2,3 </user>
1,2,3 <user>
1 ,3 <name/>
1 ,3 <phone/>
1 ,3 <email/>
1,2,3 </user>
1,2,3 <user>
1 ,3 <name/>
1 ,3 <phone/>
1 ,3 <email/>
1,2,3 </user>
1,2 </users>

1 = validated with Schema 1 (external supplier)
2 = validated with Schema 2 (to check that file "looks okay")
3 = validated with Schema 3 (for each <user>)

## /Sample XML

I know I could, using string manipulations, chop up the document,
extract the parts I need, concatenate different Schema declarations and
validate but this seems inelegant.

So is the above possible in a more XML centric manner? Maybe I should
change my approach?

Cheers

Lawrence
 
J

Johannes Koch

Lord0 said:
I *think* I need to be able to validate subsets of an XML document
using different schema. The functionality I'm trying to implement is
this.

a) External suppliers produce an XML document containing multiple User
records. The external supplier validates this entire document using
schema 1. This document is then uploaded to our system.

b) Our system then checks that the supplied document "looks okay",
minimally, using Schema 2. Schema 2 just looks for a <users> element
containing one or more <user> elements, each of which which may contain
"anything". If the document fails this validation the external supplier
receives a message like "This does not look like a valid User records
document" and processing stops.

c) Assuming the record passed b) above then each individual <user>
record is extracted and validated using Schema 3. Allowing us to say
something like "User record 1 was valid, User record 2 was invalid:
Name missing" etc.

My aren't the requirements for b) and c) in schema 1?
 
L

Lord0

My aren't the requirements for b) and c) in schema 1?

Schema 1 is the schema supplied to the external user which describes,
and requires, ALL elements from the whole instance to be present.

I dont think I can put the requirements for b) and c) in Schema 1 as
they describe subsets of the instance document.

i.e. The requirement for b) is that the instance document should
contain a <users> element containing one or more <user> elements EACH
OF WHICH can contain anything. But Schema 1 looks for a <users> element
containing one or more <user> elements EACH OF WHICH has a <name>,
<phone> and <email>

Does this make it clearer?
 
G

George Bina

Have a look at NVDL (Namespace-based Validation and Dispatching
Language). There are already a few implementations available, we just
released last week one called oNVDL. oNVDL is available also from
oXygen XML Editor version 8 so you can easily develope NVDL scripts and
test your documents from within oXygen XML Editor.

NVDL http://www.jtc1sc34.org/repository/0694c.htm
oNVDL http://www.oxygenxml.com/onvdl.html
oXygen XML Editor http://www.oxygenxml.com

Basically the idea is that you describe what fragments from the XML
document will be validated with what schema. Supported schema types in
oNVDL are XML Schema, Relax NG and Schematron.

Best Regards,
George
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top