473,794 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4722
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
1399
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
1854
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> <Node:Template Node:nodeId="nodeID"> <Node:Name Node:Comment="">Name</Node:Name> <Node:Name2 Node:Comment="">Name</Node:Name2> ...
2
1191
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 --> </users> what i like to define in schema is, that users
1
1237
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 to write blank data to that element, and then continue validating against my schema. Any ideas? -={Brian Kedersha}=-
6
2429
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 is not absolutely wonderful. So what I want to do is to validate it before I upload it. When I try and do this I get MILLIONS of errors (well lots) complaining about elements like ROOT which are part of the
0
1957
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 samples found on the web, and I'm still having no luck. Basically, the file always loads without error, even though it shouldn't be valid. Here are my various files, any help is greatly appreciated. There are some comments inline. thanks so...
2
2562
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 excel sheet wherein some of the fields are not populated. The fields that are being imported are: Full Name, first name, last name, initial (optional), userID and email address. How do i inform the users that the following records were not imported...
2
2151
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 parent value is optional. This is different from an optional child key, where the child table allows null values - in this case it's the relation itself that is optional. Strikes me as rather contrary to the principles of RI...
1
1724
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 will need to check each 20-30 text boxes if value is there or not !! Is there a way to do like define a class=mandatory and when it is found use function on it !
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.