Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Choose predefined xs:attributeGroup - Help needed

From: George Cristian Bina <george@---------.--->
To: lawrence.michel@----.--
Date: 8/8/2006 12:41:00 AM
Hi,

This is called co-occurrence constraint and it is not supported by the 
(current version of) XML Schema. You need to define a more relaxed 
schema and place the constraints at some other level, at application 
level for instance or using Schematron embedded rules. Below you can 
find a sample XML Schema with Schematron embedded rules:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <xsd:element name=" Product">
         <xsd:annotation>
             <xsd:appinfo>
                 <pattern xmlns="http://www.ascc.net/xml/schematron" 
name="">
                     <rule context="Product[@pr_name='ONE']">
                         <assert test="@pr_Info='A' or @pr_Info='B'">For 
product ONE pr_Info should be A or B.</assert>
                     </rule>
                     <rule context="Product[@pr_name='TWO']">
                         <assert test="@pr_Info='C' or @pr_Info='D'">For 
product TWO pr_Info should be C or D.</assert>
                     </rule>
                 </pattern>
             </xsd:appinfo>
         </xsd:annotation>
         <xsd:complexType>
             <xsd:attribute name="pr_name">
                 <xsd:simpleType>
                     <xsd:restriction base="xsd:string">
                         <xsd:enumeration value="ONE"/>
                         <xsd:enumeration value="TWO"/>
                     </xsd:restriction>
                 </xsd:simpleType>
             </xsd:attribute>
             <xsd:attribute name="pr_Info">
                 <xsd:simpleType>
                     <xsd:restriction base="xsd:string">
                         <xsd:enumeration value="A"/>
                         <xsd:enumeration value="B"/>
                         <xsd:enumeration value="C"/>
                         <xsd:enumeration value="D"/>
                     </xsd:restriction>
                 </xsd:simpleType>
             </xsd:attribute>
         </xsd:complexType>
     </xsd:element>
</xsd:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com

lawrence.michel@p... wrote:
> Hi all,
> 
> I'm actually trying to design an XML-Schema that should be universally
> used within form creation (Xforms, XSL-t processing, and XML validation
> check). I'm actually designing one that should be representing a graph
> of all possible valid attribute combination within an element. Below a
> simple example:
> 
> Here a basic Product element in XML:
> 
> <Product pr_name="ONE" pr_Info="A"/>
> 
> Now, according to some business rules, let's say that all products named
> "ONE" should have their pr_Info attribute set to either A or B, and all
> products named "TWO" should have their pr_Info attribute set to either C
> or D.
> 
> A possible solution is to design an XML-schema proposing a choice of all
> Product element representing all possible combination according to their
> pr_Name.
> 
> I'm looking to have to design it with the use of attribute groups, such
> as (pseudo-code below):
> 
> attributeGroupA is:
> 	Attribute name="pr_Info" value=restriction on either A or B
> attributeGroupB is:
> 	Attribute name="pr_Info" value=restriction on either C or D
> 
> Element product
> 	start choice
> 		choice 1: attribute pr_Name = ONE and attributeGroupA
> 		choice 2: attribute pr_Name = TWO and attributeGroupB
> 	end choice
> /Element
> 
> Which will correspond to validate XML data such as:
> 
> <Product pr_name="ONE" pr_Info="A"/>
> <Product pr_name="TWO" pr_Info="C"/>
> <Product pr_name="ONE" pr_Info="B"/>
> (...)
> 
> Any idea would be greatful
> 
> Best regards ;-)
> 
> Lawrence Michel
> 
> 

From sandra.martinez@n... Mon Aug 07 23:39:35 2006
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.50)
	id 


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent