-
Bug
-
Resolution: Fixed
-
P4
-
1.4.1
-
tiger
-
generic
-
generic
-
Verified
Name: eaR10174 Date: 01/16/2002
While processing well-formed XML document without DTD the validating SAXParser
invokes the method HandlerBase.warning() to report that the document has no DTD (see
test.java below). The XML 1.0 spec, 2nd edition, reads in section 2.8:
"Definition: An XML document is valid if it has an associated document type
declaration and if the document complies with the constraints expressed in it."
Since this document has no document type declaration, this statement is violated and
the document is invalid. Therefore the parser must invoked the ErrorHandler's error()
method rather than its warning() method.
This bug is found in jdk1.4.0-b91 and affects the new JCK1.4 test:
api/org_xml/sax/HandlerBase/index.html#error[error001]
------------------------------------test.java-----------------------------
import java.io.StringReader;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.InputSource;
import org.xml.sax.HandlerBase;
public class test {
static final String XML_DATA =
"<?xml version = '1.0' encoding='ISO-8859-1' standalone='yes' ?>\n"
+ "\n"
+ "<musicians>\n"
+ " <musician>\n"
+ " <name>meena</name>\n"
+ " <instrument>trumpet</instrument>\n"
+ " <NrOfRecordings quality='good' voice='sweet'\n"
+ " show='Third' testing ='ignore'></NrOfRecordings>\n"
+ " </musician>\n"
+ "\n"
+ " <?Test ProcessingInstructionTest?>\n"
+ "</musicians>\n";
public static void main (String[] args) {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(true);
SAXParser parser = parserFactory.newSAXParser();
InputSource inSource = new InputSource(new StringReader(XML_DATA));
inSource.setSystemId("doc.xml");
HandlerBase handler = new HandlerBase() {
public void warning(SAXParseException e)
throws SAXException {
System.out.println("Warning: " + e);
}
public void error(SAXParseException e)
throws SAXException {
System.out.println("Error: " + e);
}
};
parser.parse(inSource, handler);
} catch (Exception e) {
}
}
}
---------------------------------------------------------------------------
---------------------------------------------------------------------------
% java -showversion test
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
Warning: org.xml.sax.SAXParseException: Valid documents must have a <!DOCTYPE
declaration.
Error: org.xml.sax.SAXParseException: Element type "musicians" is not declared.
Error: org.xml.sax.SAXParseException: Element type "musician" is not declared.
Error: org.xml.sax.SAXParseException: Element type "name" is not declared.
Error: org.xml.sax.SAXParseException: Element type "instrument" is not declared.
Error: org.xml.sax.SAXParseException: Element type "NrOfRecordings" is not declared.
Error: org.xml.sax.SAXParseException: Attribute "quality" is not declared for element
"NrOfRecordings".
Error: org.xml.sax.SAXParseException: Attribute "voice" is not declared for element
"NrOfRecordings".
Error: org.xml.sax.SAXParseException: Attribute "show" is not declared for element
"NrOfRecordings".
Error: org.xml.sax.SAXParseException: Attribute "testing" is not declared for element
"NrOfRecordings".
---------------------------------------------------------------------------
======================================================================
While processing well-formed XML document without DTD the validating SAXParser
invokes the method HandlerBase.warning() to report that the document has no DTD (see
test.java below). The XML 1.0 spec, 2nd edition, reads in section 2.8:
"Definition: An XML document is valid if it has an associated document type
declaration and if the document complies with the constraints expressed in it."
Since this document has no document type declaration, this statement is violated and
the document is invalid. Therefore the parser must invoked the ErrorHandler's error()
method rather than its warning() method.
This bug is found in jdk1.4.0-b91 and affects the new JCK1.4 test:
api/org_xml/sax/HandlerBase/index.html#error[error001]
------------------------------------test.java-----------------------------
import java.io.StringReader;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.InputSource;
import org.xml.sax.HandlerBase;
public class test {
static final String XML_DATA =
"<?xml version = '1.0' encoding='ISO-8859-1' standalone='yes' ?>\n"
+ "\n"
+ "<musicians>\n"
+ " <musician>\n"
+ " <name>meena</name>\n"
+ " <instrument>trumpet</instrument>\n"
+ " <NrOfRecordings quality='good' voice='sweet'\n"
+ " show='Third' testing ='ignore'></NrOfRecordings>\n"
+ " </musician>\n"
+ "\n"
+ " <?Test ProcessingInstructionTest?>\n"
+ "</musicians>\n";
public static void main (String[] args) {
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(true);
SAXParser parser = parserFactory.newSAXParser();
InputSource inSource = new InputSource(new StringReader(XML_DATA));
inSource.setSystemId("doc.xml");
HandlerBase handler = new HandlerBase() {
public void warning(SAXParseException e)
throws SAXException {
System.out.println("Warning: " + e);
}
public void error(SAXParseException e)
throws SAXException {
System.out.println("Error: " + e);
}
};
parser.parse(inSource, handler);
} catch (Exception e) {
}
}
}
---------------------------------------------------------------------------
---------------------------------------------------------------------------
% java -showversion test
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
Warning: org.xml.sax.SAXParseException: Valid documents must have a <!DOCTYPE
declaration.
Error: org.xml.sax.SAXParseException: Element type "musicians" is not declared.
Error: org.xml.sax.SAXParseException: Element type "musician" is not declared.
Error: org.xml.sax.SAXParseException: Element type "name" is not declared.
Error: org.xml.sax.SAXParseException: Element type "instrument" is not declared.
Error: org.xml.sax.SAXParseException: Element type "NrOfRecordings" is not declared.
Error: org.xml.sax.SAXParseException: Attribute "quality" is not declared for element
"NrOfRecordings".
Error: org.xml.sax.SAXParseException: Attribute "voice" is not declared for element
"NrOfRecordings".
Error: org.xml.sax.SAXParseException: Attribute "show" is not declared for element
"NrOfRecordings".
Error: org.xml.sax.SAXParseException: Attribute "testing" is not declared for element
"NrOfRecordings".
---------------------------------------------------------------------------
======================================================================