Hi Mukul,
The jaxp.SourceValidator sample creates a SchemaFactory for XML Schema 1.0
by default. There's no identifier for an XML Schema 1.1 document. You need
to explicitly select an XML Schema 1.1 processor if you want to load and
use it.
For example:
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
public class XMLSchema11Test {
public static void main (String [] args) {
try {
System.setProperty(
"javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema/v1.1",
"org.apache.xerces.jaxp.validation.XMLSchema11Factory");
SchemaFactory sf = SchemaFactory.newInstance(
"http://www.w3.org/2001/XMLSchema/v1.1");
Schema s = sf.newSchema(new StreamSource(args[0]));
Validator v = s.newValidator();
v.validate(new StreamSource(args[1]));
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Thanks.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [email protected]
E-mail: [email protected]
"Mukul Gandhi" <[email protected]> wrote on 12/17/2008 12:55:42 AM:
> Hi Michael,
> I was using a slightly older SVN code for Xerces. Now I have
> downloaded today the latest Xerces SVN code. I am creating a file
> like, xercesImpl.jar from the latest SVN code and using it.
>
> I am now trying the below examples (with corrections in the Schema as
> you have pointed).
>
> XML file:
>
> <PERSON xsi:noNamespaceSchemaLocation="person.xsd"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <FNAME>Mukul</FNAME>
> <LNAME>Gandhi</LNAME>
> <DOB>1999-06-02</DOB>
> <ADDRESS type="short">
> <street1>ddd</street1>
> <street2>aaa</street2>
> <city>aaa</city>
> </ADDRESS>
> </PERSON>
>
> Schema:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="PERSON" type="PersonType" />
>
> <xs:complexType name="PersonType">
> <xs:sequence>
> <xs:element name="FNAME" type="xs:string" />
> <xs:element name="LNAME" type="xs:string" />
> <xs:element name="DOB" type="xs:date" />
> <xs:element name="ADDRESS" type="Address">
> <xs:alternative test="@type='short'" type="ShortAddress"/>
> <xs:alternative test="@type='long'" type="LongAddress"/>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="Address">
> <xs:sequence>
> <xs:element name="street1" type="xs:string" />
> <xs:element name="street2" type="xs:string" minOccurs="0" />
> </xs:sequence>
> <xs:attribute name="type" type="xs:string"/>
> </xs:complexType>
>
> <xs:complexType name="ShortAddress">
> <xs:complexContent>
> <xs:extension base="Address">
> <xs:sequence>
> <xs:element name="city" type="xs:string" />
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> <xs:complexType name="LongAddress">
> <xs:complexContent>
> <xs:extension base="Address">
> <xs:sequence>
> <xs:element name="city" type="xs:string" />
> <xs:element name="state" type="xs:string" />
> <xs:element name="pin" type="xs:string" />
> <xs:element name="country" type="xs:string" />
> </xs:sequence>
> </xs:extension>
> </xs:complexContent>
> </xs:complexType>
>
> </xs:schema>
>
> When I perform the validation (using the jaxp.SourceValidator
> utility), I get following errors:
>
> [Error] person.xsd:11:69: s4s-elt-must-match.1: The content of
> 'ADDRESS' must match (annotation?, (simpleType | complexType)?,
> alternative*, (unique | key | keyref)*)). A problem was found starting
> at: alternative.
> [Error] person.xml:8:8: cvc-complex-type.2.4.d: Invalid content was
> found starting with element 'city'. No child element is expected at
> this point.
>
> I saw following code in the Java file, XSDElementTraverser.java
>
> if (fSchemaHandler.fSchemaVersion == Constants.SCHEMA_VERSION_1_1) {
> while (childName.equals(SchemaSymbols.ELT_ALTERNATIVE)) {
> fSchemaHandler.fTypeAlternativeTraverser.traverse(child,
> element, schemaDoc, grammar);
>
> It seems to me, that TypeAlternativeTraverser is triggered only when
> version 1.1 is specified in the XSD file. How should I specify this
> information in the Schema file?
>
> Thanks for your help ...
>
> On Wed, Dec 17, 2008 at 1:39 AM, Michael Glavassevich (JIRA)
> <[email protected]> wrote:
> >
> > [ https://issues.apache.org/jira/browse/XERCESJ-1351?page=com.
> atlassian.jira.plugin.system.issuetabpanels:comment-
> tabpanel&focusedCommentId=12657142#action_12657142 ]
> >
> > Michael Glavassevich commented on XERCESJ-1351:
> > -----------------------------------------------
> >
> > Mukul, I get different behaviour when I try your test. The only
> error I'm getting is:
> >
> > org.xml.sax.SAXParseException: cvc-minLength-valid: Value '' with
> length = '0' is not facet-valid with respect to minLength '1' for
> type 'shortString'.
>
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]