Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > General entity references and Schema validation problem (using Xerces2)

Reply
Thread Tools

General entity references and Schema validation problem (using Xerces2)

 
 
Zandy Marantal
Guest
Posts: n/a
 
      08-27-2003
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 xmlnssi="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 xmlnss="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();
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Entity, problem with entity key ThatsIT.net.au ASP .Net 1 09-07-2009 02:20 AM
Well-formedness and undeclared general entity references Stanimir Stamenkov XML 5 04-10-2009 02:51 PM
How to relate a SQL based entity with an Object based entity in Entity Framework markla ASP .Net 1 10-06-2008 09:42 AM
Problem with schema-validation and property "http://apache.org/xml/properties/schema/external-schemaLocation" Markus Java 1 11-23-2005 02:41 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57