Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6558451

jaxp issue 30: none value recognition of minOccurs and maxOccurs

    • b01
    • generic
    • generic
    • Verified

        Originally reported on java.net, jaxp issue 30:
        I have an application where xml streams needs to be validated against xsd-schemas.
        Using JDK 1.5 (jdk1.5.0_07) this works well and the streams are correctly validated.

        When I use Java 1.6 (build 1.6.0-b105) the minOccurs and maxOccurs seams to be
        skipped from the validation process and the xml is always reported as valid.

        Here is a snippet of my code:

        File xmlFile = new File("occurs.xml");

        SchemaFactory factory=SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new File("occurs.xsd"));

        // get a DOM factory
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        // configure the factory
        dbf.setNamespaceAware(true);

        // set schema on the factory
        dbf.setSchema(schema);

        DocumentBuilder documentBuilder = dbf.newDocumentBuilder();

        // Check the document
        try {
        documentBuilder.parse(xmlFile);
        System.out.println(xmlFile.getName() + " is valid.");
        }
        catch (SAXException ex) {
        System.out.println(xmlFile.getName() + " is not valid because ");
        System.out.println(ex.getMessage());
        }

        // And the corresponding xml and xsd.

        occurs.xml

        <?xml version="1.0" encoding="ISO-8859-1"?>
         
        <persons>
         
        <person>
        <full_name>Hege Refsnes</full_name>
        <child_name>Cecilie</child_name>
        </person>
         
        <person>
        <full_name>Tove Refsnes</full_name>
        <child_name>Hege</child_name>
        <child_name>Stale</child_name>
        <child_name>Jim</child_name>
        <child_name>Borge</child_name>
        </person>
         
        <person>
        <full_name>Stale Refsnes</full_name>
        </person>
         
        </persons>




        occurs.xsd

        <?xml version="1.0" encoding="ISO-8859-1"?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="qualified">
         
        <xs:element name="persons">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="person" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="full_name" type="xs:string"/>
                    <xs:element name="child_name" type="xs:string" minOccurs="0"
        maxOccurs="3"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
         
        </xs:schema>
         



        Java 1.5 reports:
        occurs.xml is not valid because
        cvc-complex-type.2.4.d: Invalid content was found starting with element
        'child_name'. No child element is expected at this point.

        while Java 1.6 reports:
        occurs.xml is valid.

        I browsed the JAXP Project Page to find the differences from JAXP 1.3 is
        included in J2SE 5.0 and the implementation of JAXP 1.4 is part of Java SE 6.0
        but found nothing linked to my problem.

              spericas Santiago Pericasgeertsen
              joehw Joe Wang
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: