473,378 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 2831
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.