GilliVilla
GilliVilla

Reputation: 5090

XML Schema validation - intra-field validation

This is the scenario/problem I am trying to solve - Within a sequence of elements in my XSD I have an element- say XYZ which can be nillable if the one of the preceding element - say ABC - has a certain value - say "Alpha". If that preceding element - ABC has a different value then the element XYZ must be not nillable.

What is the best approach to solve this problem?

I am using C# & SQL Server.

Is it possible to define new attributes within a XSD?

Upvotes: 1

Views: 302

Answers (1)

Paul
Paul

Reputation: 4259

Really an XSD should be fixed to control the structure and format of the elements and attributes. What you are attempting to do is implement business rules, which cannot be validated using an XSD.

However, there is a framework available for implementing business rules in XML, it is an ISO standard called Schematron. Schematron basically uses a combination of XPath to implement the logic and XSLT to perform the validation.

There is a .NET project for this know as Schematron.NET.

This may be interesting reading 'Improving XML Document Validation with Schematron'.

Upvotes: 4

Related Questions