473,698 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validating element occurance based on attribute values

Hi,

I have a situation where i would like to validate the occurance of certain
elements, based on the value of an attribute.

What is the "best" way to handle such validations? I am fairly new to XML
and its validation techniques. Schematron would probably do the trick, but i
havent found a straight forward way that solves my problem.

Anybody ideas - recommendations ?

Thanks in advance!
Jul 20 '05 #1
1 1504


UndoMiel wrote:
I have a situation where i would like to validate the occurance of certain
elements, based on the value of an attribute.

What is the "best" way to handle such validations? I am fairly new to XML
and its validation techniques. Schematron would probably do the trick, but i
havent found a straight forward way that solves my problem.


Well schematron should indeed allow that, the summary at
http://www.schematron.com/
explicitly says

Attributes
W3C XML Schemas does not support several idiomatic uses of
attributes: using an attribute to constrain or select an element's
content model, or using using constrainted data values with various
units. It provides no advance on DTDs in this area.

when trying to present capabilities of schematron.

I have never used schematron before but I have just tried to write a
schema as follows

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron">
<pattern name="Test that attribute type=&quot;net& quot; has child
element home">
<rule context="person ">
<report test="@type = 'net' and not(home)">nece ssary child
element home is missing</report>
</rule>
</pattern>
</schema>

which reports an error if a <person> element has an attribute type with
value 'net' but no child element <home>.

An example XML document that should raise an error during validation is

<?xml version="1.0" encoding="UTF-8"?>
<root>
<person type="net">
<name>Kibo</name>
<home>http://www.kibo.com/</home>
</person>
<person type="net">
<name>Xibo</name>
</person>
<person type="normal">
<name>Maho</name>
</person>
</root>

and indeed when I use Jing from
http://www.thaiopensource.com/relaxng/jing.html to perform a validation
it says

PathToFile\test 2004073102.xml: 7: error: report:
necessary child element home is missing

so it correctly gives an error for the element <person> in line 7 as to
not having a child element <home>.
You can find schematron examples at
http://www.zvon.org/xxl/SchematronTu...neral/toc.html

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
3896
by: Toni Mcintyre | last post by:
i'm having 2 problems with the http://validator.w3.org 1. if i have: <meta http-equiv="Content-Script-Type" content="text/javascript"> then why do i need <script type=text/javascript> everywhere??? i'm writing most of my code by hand, so this is a lot of extra typing or global search and replace later 2. the other problem is with my include files: i usually <script src="foo.js"></script>
6
6324
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
2
5100
by: and | last post by:
Hi I have been validating all day most things are cool but I cant get by this problem. One I have listed the script (JAVASCRIPT ) in all the right placesnot a prob but the validator insists on going through t findind < (less than) in the code. why is it going through the script the scripts been tagged correctly? Also in the body where the link to the script is there is a table givng
6
2421
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
1
2970
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. The problem I am having is that the validation event fires for each node in the xml. It seems to be completely ignoring the schema that I have used. I'm wondering if I need to do something extra to tell the xml which schema to use.
3
6057
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom errors saying what happened and where...... is it possible to do that ? for eg. if the Attribute is missing or invalid in the following element <Watch ID="999d999">
1
4239
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end of the post. I am using VS.net 2003, .Net 1.1, Win2k Server I have a simple schema and a simple XML document.
1
5928
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that if when the list/menu (attribute6) value is "Ja" then to make the TextField Pas Nr (attribute4) required. And if when the list/menu (attribute6) value is "Nee" to make the TextField Pas Nr (attribute4) not required.
4
1299
by: Labm1ce | last post by:
' First create Xml document Dim oXmlDocument As New System.Xml.XmlDocument oXmlDocument.LoadXml("<Trees><Oak TreeType=""deciduous""></Oak></Trees>") oXmlDocument.Save("Trees.xml") ' .NET save xml document with spaces <Trees> <Oak TreeType=""deciduous"">
0
8683
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
8609
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
9170
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...
1
8901
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
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();...
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.