United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6467424 javax.xml.validation.Validator does not augment.
6467424 : javax.xml.validation.Validator does not augment.

Details
Type:
Bug
Submit Date:
2006-09-05
Status:
Resolved
Updated Date:
2012-04-25
Project Name:
JDK
Resolved Date:
2009-02-10
Component:
xml
OS:
generic,windows_2000
Sub-Component:
javax.xml.validation
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6,6u11
Fixed Versions:
1.4.0

Related Reports
Backport:
Backport:
Backport:

Sub Tasks

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.
                                     
2009-02-06
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.
                                     
2006-09-06
EVALUATION

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



Hardware and Software, Engineered to Work Together