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

javax.xml.validation.Validator does not augment.

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.4
    • CPU:
      generic, x86
    • OS:
      generic, windows_2000

      Backports

        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 ----------

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                joehw Joe Wang
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: