JDK-6467424 : javax.xml.validation.Validator does not augment.
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.validation
  • Affected Version: 6,6u11
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_2000
  • CPU: generic,x86
  • Submitted: 2006-09-05
  • Updated: 2012-04-25
  • Resolved: 2009-02-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
1.4.0 1.4Fixed 6u13-revFixed 7Fixed
Description
FULL PRODUCT VERSION :


ADDITIONAL OS VERSION INFORMATION :
Windows 2000

A DESCRIPTION OF THE PROBLEM :
The JAXP 1.3 Validation API in the javax.xml.validation package provides a method in Validator to augment an XML document.
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
An XML document des not get augmented.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the XSDAugmenter application with catalog.xml and catalog.xsd.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An augmented XML document
ACTUAL -
An XML document that is not augmented.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import javax.xml.transform.dom.*;
import javax.xml.validation.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;

public class XSDAugmenter {

    public static void main(String[] args)
      throws SAXException, IOException, ParserConfigurationException {

          try{
        SchemaFactory factory
         = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        File schemaLocation = new File("c:/catalog.xsd");
        Schema schema = factory.newSchema(schemaLocation);
        Validator validator = schema.newValidator();
        
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        domFactory.setNamespaceAware(true); // never forget this
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        Document doc = builder.parse(new File("c:/catalog.xml"));
        
        DOMSource source = new DOMSource(doc);
        DOMResult result = new DOMResult();

        
            validator.validate(source, result);
            Document augmented = (Document) result.getNode();

            TransformerFactory tFactory =
                TransformerFactory.newInstance();
           
            Transformer transformer = tFactory.newTransformer();
 
            DOMSource domSource = new DOMSource(augmented);
            StreamResult streamResult = new StreamResult(System.out);
            transformer.transform(domSource, streamResult);
}
        
        catch (TransformerConfigurationException e) {
          
           System.out.println(e.getMessage());

          
      
        } catch (TransformerException e) {
           
           System.out.println(e.getMessage());

           
         } catch (SAXException e) {
           System.out.println(e.getMessage() );

        } catch (ParserConfigurationException e) {
             System.out.println(e.getMessage() );
            
        } catch (IOException e) {
          
           System.out.println(e.getMessage());
        }

}}

catalog.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--A OnJava Journal Catalog-->

<catalog
   
   title="OnJava.com" publisher="O'Reilly">
 <journal date="April 2004">
   <article>
    <title></title>
    <author>Narayanan Jayaratchagan</author>
   </article>
 </journal>
 <journal date="January 2004">
   <article>
    <title></title>
    <author>Daniel Steinberg</author>
   </article>
 </journal>
</catalog>

catalog.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="catalog">
   <xs:complexType>
    <xs:sequence>
     <xs:element ref="journal" minOccurs="0"
maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="title" type="xs:string"/>
    <xs:attribute name="publisher"  type="xs:string"/>
   </xs:complexType>
  </xs:element>
  <xs:element name="journal">
   <xs:complexType>
    <xs:sequence>
     <xs:element ref="article" minOccurs="0"
        maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="date" type="xs:string"/>
   </xs:complexType>
  </xs:element>
  <xs:element name="article">
   <xs:complexType>
    <xs:sequence>
     <xs:element name="title" type="xs:string" minOccurs="1" default="Schema Validation"/>
     <xs:element ref="author" minOccurs="0"
        maxOccurs="unbounded"/>
    </xs:sequence>
   </xs:complexType>
  </xs:element>
  <xs:element name="author" type="xs:string"/>
</xs:schema>
---------- END SOURCE ----------

Comments
EVALUATION The issue appears in jdk6 update releases as well as in jaxp 1.4.
06-02-2009

EVALUATION I've tried this with J2SE Update 7-b03 and the augmentation seems to work fine. Here is the output I get: <?xml version="1.0" encoding="UTF-8"?><catalog publisher="O'Reilly" title="OnJava.com"><journal date="April 2004"><article><title>Schema Validation</title><author>Narayanan Jayaratchagan</author></article></journal><journal date="January 2004"><article><title>Schema Validation</title><author>Daniel Steinberg</author></article></journal></catalog> In particular, the value of element title is "Schema Validation". Same result with the latest J2SE 6.0 build. Please include more information about JRE platform, version of JAXP, etc.
06-09-2006

EVALUATION Looks like the submitter is correct. We should be augmenting the element default value.
05-09-2006