Hi Michael, Khaled, Thanks for the answer. Ok, so if I get it right, Xerces2-j is doing it the right way from what I ask him. I tried to use an assertion but I had problem with this, maybe you could help me here.
I can't use assert within the definition of an element (meaning at the same place where I used my alternative), that makes sense but if I can't do it before choosing for my "future" element, I can't be sure that the element attribute would follow my rules. So I got back to the same problem as before, no errors are being thrown because the element created does not get any type from my alternative rules... So actually, the only way I made it work for me, is to create a new (3rd) alternative rule: <xs:alternative test="(@attribute ne 'value1') and (@attribute ne 'value2')" type="myElement.error" /> And have this complex type (myElement.error) the exact same way as it would be a combination of "myElement.value1" and "myElement.value2" with a restriction of the value of attribute (only "value1" and "value2" allowed) - which sounds strange because my rules should specify this before... If you have a better way to do this, I would be happy to hear it. Thanks, Yoann On Mon, May 3, 2010 at 8:16 PM, Khaled Noaman <knoa...@ca.ibm.com> wrote: > > Hi Yoann, > > It seems you are getting the desired behavior, i.e. the type assigned to > the element is xs:error. Since xs:error is just a special simple type > definition, whose name is error in the XSD namespace, Xerces-J is throwing > the right error message (no attributes are allowed for simple types). You > are looking for a specific message, which in these case is an invalid value > for an attribute. You would need to use assertions to specify that your > attribute can only be of two values and you would probably get an error > message telling you that the assertion failed. > > Regards, > Khaled > > > > > From: Michael Glavassevich/Toronto/i...@ibmca To: > j-users@xerces.apache.org Date: 05/03/2010 01:41 PM Subject: Re: XSD1.1 > alternative test and errors > ------------------------------ > > > > Hi Yoann, > > Are you using a binary built from the XML Schema 1.1 development branch > [1]? We're still working on implementing these features. It's possible > support for xs:error isn't there yet or isn't correct. I haven't looked at > this much though. Khaled, Mukul and/or Hiranya would probably have more > insight. > > Thanks. > > [1] *http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/ > * <http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/> > > Michael Glavassevich > XML Parser Development > IBM Toronto Lab > E-mail: mrgla...@ca.ibm.com > E-mail: mrgla...@apache.org > > yoann moranville <yoann.moranvi...@gmail.com> wrote on 05/03/2010 09:03:45 > AM: > > > Dear all, > > > > I am facing an issue while validating using XSD1.1. > > I want to decide on the type of an element depending on one of its > > attribute value: > > > > <xs:element name="myElement"> > > <xs:alternative test="@attribute = 'value1'" type="myElement.value1" > /> > > <xs:alternative test="@attribute = 'value2'" type="myElement.value2" > /> > > </xs:element> > > > > Now that works, both types "myElement.value1" and "myElement.value2" > > are complex types. > > > > However, I realized that if I have @attribute = 'value3', no errors > > are being thrown so I wanted to add a new alternative rule: > > <xs:alternative test="(@attribute ne 'value1') or (@attribute ne > > 'value2')" type="xs:error" /> > > > > But when that occurs, the validation error begin thrown are not what I > > am waiting for, it says that my attributes are not correct since the > > type of myElement is of simple type. > > > > So how could I throw an error saying that my @attribute is not of > > correct values? > > > > Thank you, > > Yoann > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: j-users-unsubscr...@xerces.apache.org > > For additional commands, e-mail: j-users-h...@xerces.apache.org > >