472,787 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,787 software developers and data experts.

General entity references and Schema validation problem (using Xerces2)

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();
}
}
}
Jul 20 '05 #1
1 2804
janey
1
I'm having the same problem. Can you share the solution with me? Thanks!
Sep 1 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert Lintner | last post by:
Hi, I woult like to switch from DTD to XML-Schema and am looking for an equivalent to external ENTITY for composition of an xml file from modules --- my.dtd -- <?xml version="1.0"...
1
by: Ole Hedegaard | last post by:
Hi, I've been looking into the Xerces documentation, and to my surprise it seems that it is impossible to validate an XML document againts an XML Schema without having a schemaLocation (or...
6
by: Phil Jarvis | last post by:
I have an XML Schema with regular expressions. e.g. <xsd:pattern value="{1}*"/> I have other patterns in the same schema document which share regular expression substructure, like the string...
2
by: Ken Philips | last post by:
As far as I know the Schema Object Model (SOM) is only working for the MSXML Parser together with CSharp or VisualBasic but not Java. Is there a similar Tool/Spec/Api for the Java World? Ken
9
by: Stanimir Stamenkov | last post by:
Using Xerces2 Java I'm trying to validate a CSV data following an XNI example <http://xml.apache.org/xerces2-j/xni-config.html#examples>. The CSV scanner generates XML tree events like: <csv>...
2
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the...
9
by: lkrubner | last post by:
Can't get this RSS feed clean: http://www.whatisliberalism.com/pdsFiles/page2533.xml Why is it dying? Some users write posts in Microsoft Word, then copy and paste their post to the web...
1
by: i.am.thor | last post by:
Does anyone know of a way to force validation of an XML file if the schemaLocation attribute is not set in the document? For example, I'm trying to use the loadGrammar() function of the xerces...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.