[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug xml/31819] New: XML that is invalid according to schema parses succ
From: |
fullung at gmail dot com |
Subject: |
[Bug xml/31819] New: XML that is invalid according to schema parses successfully |
Date: |
4 May 2007 16:59:01 -0000 |
Test case extracted from the Spring Framework tests. Tested with the latest GNU
Classpath from CVS as of 2007/05/04 18:00 GMT+2. The required schema can be
found at:
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
Sun JDK 1.5.0_10 says:
org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was
found starting with element 'foobar'. One of
'{"http://www.springframework.org/schema/beans":description,
"http://www.springframework.org/schema/beans":import,
"http://www.springframework.org/schema/beans":alias,
"http://www.springframework.org/schema/beans":bean,
WC[##other:"http://www.springframework.org/schema/beans"]}' is expected.
GNU Classpath/IKVM.NET parses the document without an error.
Code:
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class InvalidXml {
private static final String SCHEMA_LANGUAGE_ATTRIBUTE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
private static final String XSD_SCHEMA_LANGUAGE =
"http://www.w3.org/2001/XMLSchema";
private static class MyEntityResolver implements EntityResolver {
public InputSource resolveEntity(String publicId, String
systemId)
throws SAXException, IOException {
return new InputSource(new
FileInputStream("spring-beans-2.0.xsd"));
}
}
private static class MyErrorHandler implements ErrorHandler {
public void error(SAXParseException exception) throws
SAXException {
System.out.println(exception);
}
public void fatalError(SAXParseException exception) throws
SAXException {
System.out.println(exception);
}
public void warning(SAXParseException exception) throws
SAXException {
System.out.println(exception);
}
}
public static void main(String[] args) throws Exception {
final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<beans
xmlns=\"http://www.springframework.org/schema/beans\" "
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+
"xsi:schemaLocation=\"http://www.springframework.org/schema/beans "
+
"http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">"
+ "<foobar/></beans>";
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute(SCHEMA_LANGUAGE_ATTRIBUTE,
XSD_SCHEMA_LANGUAGE);
DocumentBuilder docBuilder = factory.newDocumentBuilder();
docBuilder.setErrorHandler(new MyErrorHandler());
docBuilder.setEntityResolver(new MyEntityResolver());
InputSource inputSource = new InputSource(new
ByteArrayInputStream(xml.getBytes()));
Document doc = docBuilder.parse(inputSource);
}
}
--
Summary: XML that is invalid according to schema parses
successfully
Product: classpath
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: xml
AssignedTo: dog at gnu dot org
ReportedBy: fullung at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31819
- [Bug xml/31819] New: XML that is invalid according to schema parses successfully,
fullung at gmail dot com <=