473,395 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 4680
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Piers Chivers | last post by:
Hi, I have XML like <SomeElement> <Value>5</Value> <Value>3</Value> <Value>7</Value> </SomeElement> I want to define the schema to say that the <Value>s must contain at least
1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
2
by: Th.-Fischer | last post by:
hi, i have this xml structure <users> <user id="root"/> <!-- mandatory! --> <user id="a"/> <!-- optional --> <user id="b"/> <!-- optional --> <user id="c"/> <!-- optional -->...
1
by: Brian Kedersha | last post by:
I am receiving XML data that I would like to validate against my schema and write at the same time. Some of the data is optional, if the data in the optional elements is incorrect, I would like...
6
by: Iain | last post by:
I've got a system which takes an XML file, translates it into an update gram and then loads it into my database with SQLXML3 (all in dot net). But it's fragile. And the SQLXML 3 error reporting...
0
by: Sahmiac | last post by:
Hello Everyone, I'm sure this question has been asked a million times, but I'm going crazy trying to get my xml validation to work. I've spent the day reading msdn, the dot net documentation and...
2
by: lrheeza | last post by:
Hello everyone, I am a newbie at MS Access and I need help!!! I am importing an excel file using Import functionality in MS Access, all the fields are required but there are instances in the...
2
by: BD | last post by:
I'm working with a data model which is managed in the AllFusion ERwin tool. Within the modeler, some of the FK relationships are 'non-mandatory' - which is to say that for a given child value, a...
1
pradeepjain
by: pradeepjain | last post by:
Hii , I have a form which has 20-30 textboxes which are mandatory ! is there a way of validating mandatory fields in easier ways by using a single function or some thing like tht ! bcos i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.