|
Quick Lists
|
|
Bug ID:
|
6467424
|
|
Votes
|
1
|
|
Synopsis
|
javax.xml.validation.Validator does not augment.
|
|
Category
|
jaxp:validation
|
|
Reported Against
|
|
|
Release Fixed
|
1.4,
6u13-rev(b05) (Bug ID:2172356)
, 6u14(b05) (Bug ID:2176329)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
2-High
|
|
Related Bugs
|
|
|
Submit Date
|
05-SEP-2006
|
|
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 ----------
Posted Date : 2006-09-05 18:27:37.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
Looks like the submitter is correct. We should be augmenting the element default value.
Posted Date : 2006-09-05 22:13:03.0
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.
Posted Date : 2006-09-06 19:00:30.0
The issue appears in jdk6 update releases as well as in jaxp 1.4.
Posted Date : 2009-02-06 20:00:52.0
|
|
Comments
|
Submitted On 08-SEP-2006
marlysa
I have the same issue. I am using J2SE 1.5.0_08 b03.
Submitted On 19-SEP-2006
dvohra09
Thanks for fixing the bug. The agumentation bug was was in jdk1.5.0_06.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |