Z
Zandy Marantal
Hello everyone,
I'm having trouble using Xerces2(2.4, 2.5) when validating against an
XML schema if a general entity reference is defined within the XML
file.
The error I'm getting is this: "org.xml.sax.SAXParseException: Element
type "personnel" must be declared."
Xerces1(1.4.3, 1.4.4) doesn't have an issue with this. As is XML Spy.
Is there any other Xerces feature/property that I need to enable/set?
It works if I remove the entity reference "test".
Below is the cut-down version XML file and the schema:
(personal.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel [
<!ENTITY test "test123">
]>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="personal.xsd">
<person id="Big.Boss">
<name>
<family>Boss&test;</family>
<given>Big</given>
</name>
</person>
</personnel>
==========================================================
(personal.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="personnel">
<xs:complexType>
<xs:sequence>
<xs:element ref="person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="name">
<xs:complexType>
<xs:all>
<xs:element ref="family"/>
<xs:element ref="given"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="family" type="xs:string"/>
<xs:element name="given" type="xs:string"/>
</xs:schema>
========================================================
(java code)
package jdomexample;
import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.apache.xerces.parsers.SAXParser;
public class configParser {
private static final String DEFAULT_SAX_DRIVER_CLASS =
"org.apache.xerces.parsers.SAXParser";
private String saxDriverClass;
private SAXBuilder builder;
// CONSTRUCTOR - create instance of SAXBuilder for use in the rest
of the program
public configParser(String saxDriverClass) {
builder = new SAXBuilder(saxDriverClass, true);
builder.setFeature("http://xml.org/sax/features/validation",
true);
builder.setFeature("http://apache.org/xml/features/validation/schema",
true);
}
public void read(String filename) throws IOException, JDOMException
{
Document doc = builder.build(new File(filename));
Element root = doc.getRootElement();
}
// This provides a static entry point for reading an XML file using
JDOM
public static void main(String args[]) {
PrintStream out = System.out;
if (args.length != 1) {
out.println("Usage: jdomexample.configParser [xml config
file]");
return;
}
// Load filename and SAX driver class
String filename = args[0];
String saxDriverClass = DEFAULT_SAX_DRIVER_CLASS;
// Create an instance of the tester and test
try {
configParser cp = new configParser(saxDriverClass);
cp.read(filename);
} catch (JDOMException e) {
if (e.getCause() != null) {
e.getCause().printStackTrace();
} else {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
I'm having trouble using Xerces2(2.4, 2.5) when validating against an
XML schema if a general entity reference is defined within the XML
file.
The error I'm getting is this: "org.xml.sax.SAXParseException: Element
type "personnel" must be declared."
Xerces1(1.4.3, 1.4.4) doesn't have an issue with this. As is XML Spy.
Is there any other Xerces feature/property that I need to enable/set?
It works if I remove the entity reference "test".
Below is the cut-down version XML file and the schema:
(personal.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel [
<!ENTITY test "test123">
]>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="personal.xsd">
<person id="Big.Boss">
<name>
<family>Boss&test;</family>
<given>Big</given>
</name>
</person>
</personnel>
==========================================================
(personal.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="personnel">
<xs:complexType>
<xs:sequence>
<xs:element ref="person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="name">
<xs:complexType>
<xs:all>
<xs:element ref="family"/>
<xs:element ref="given"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="family" type="xs:string"/>
<xs:element name="given" type="xs:string"/>
</xs:schema>
========================================================
(java code)
package jdomexample;
import java.io.*;
import java.util.*;
import org.jdom.*;
import org.jdom.input.*;
import org.apache.xerces.parsers.SAXParser;
public class configParser {
private static final String DEFAULT_SAX_DRIVER_CLASS =
"org.apache.xerces.parsers.SAXParser";
private String saxDriverClass;
private SAXBuilder builder;
// CONSTRUCTOR - create instance of SAXBuilder for use in the rest
of the program
public configParser(String saxDriverClass) {
builder = new SAXBuilder(saxDriverClass, true);
builder.setFeature("http://xml.org/sax/features/validation",
true);
builder.setFeature("http://apache.org/xml/features/validation/schema",
true);
}
public void read(String filename) throws IOException, JDOMException
{
Document doc = builder.build(new File(filename));
Element root = doc.getRootElement();
}
// This provides a static entry point for reading an XML file using
JDOM
public static void main(String args[]) {
PrintStream out = System.out;
if (args.length != 1) {
out.println("Usage: jdomexample.configParser [xml config
file]");
return;
}
// Load filename and SAX driver class
String filename = args[0];
String saxDriverClass = DEFAULT_SAX_DRIVER_CLASS;
// Create an instance of the tester and test
try {
configParser cp = new configParser(saxDriverClass);
cp.read(filename);
} catch (JDOMException e) {
if (e.getCause() != null) {
e.getCause().printStackTrace();
} else {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}