469,579 Members | 1,281 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Validating a XML Schema that has mandatory & optional fields

Hi

I am wondering if anybody has come accross this problem before,
basically I have to validate a xml schema (not the data, this is done
at a later stage). The only problem is that there are Mandatory fields,
and Optional fields. Thus I don't think a DTD can be used (as a valid
xml file can just have the mandatory fields).
I have a designed a small validation engine in perl which I'm about to
start to code up, but thought I might check to see if there is
something already developed... (Also spending half a day transfering a
xml schema to a flat file (which contain the mandatory & optional
information) and then loading the flat file into a database table I'm
starting to wonder if there is a better solution!!.)
An example would be

Assume Tags 1 & 2 are Mandatory and Tag3 Optional

<Tag1>
<Tag2> </Tag2>
<Tag3> </Tag3>
<Tag1>

But Also the below is also valid

<Tag1>
<Tag2> </Tag2>
<Tag1>

If anybody has got any idea's or suggestions they would be greatly
appreciated. Thanking you in advance for time and comments.
Many Thanks

David

Apr 11 '06 #1
1 4218
Le Tubs wrote:
Hi

I am wondering if anybody has come accross this problem before,
basically I have to validate a xml schema (not the data, this is done
at a later stage). The only problem is that there are Mandatory fields,
and Optional fields.
XML doesn't have "fields". See the warning in
http://xml.silmaril.ie/authors/databases/
Thus I don't think a DTD can be used (as a valid
xml file can just have the mandatory fields).
A DTD can specify optional element types.
I have a designed a small validation engine in perl which I'm about to
start to code up, but thought I might check to see if there is
something already developed... (Also spending half a day transfering a
xml schema to a flat file (which contain the mandatory & optional
information) and then loading the flat file into a database table I'm
starting to wonder if there is a better solution!!.)
An example would be

Assume Tags 1 & 2 are Mandatory and Tag3 Optional

<Tag1>
<Tag2> </Tag2>
<Tag3> </Tag3>
<Tag1>

But Also the below is also valid

<Tag1>
<Tag2> </Tag2>
<Tag1>


A DTD to describe this would be:

<!ELEMENT Tag1 (Tag2,Tag3?)>
<!ELEMENT Tag2 (#PCDATA)
<!ELEMENT Tag3 (#PCDATA)

Entia non sunt multiplicanda pręter necessitatem.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Apr 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Th.-Fischer | last post: by
1 post views Thread by Brian Kedersha | last post: by
6 posts views Thread by Iain | last post: by
pradeepjain
1 post views Thread by pradeepjain | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.