473,396 Members | 1,784 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,396 software developers and data experts.

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 1485


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)">necessary 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\test2004073102.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
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>...
6
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,...
2
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...
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...
1
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. ...
3
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...
1
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...
1
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...
4
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...
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
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...
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.