General entity references and Schema validation problem (using Xerces2)

Discussion in 'XML' started by Zandy Marantal, Aug 27, 2003.

  1. 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();
    }
    }
    }
    Zandy Marantal, Aug 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,475
    Markus
    Nov 23, 2005
  2. Gerben
    Replies:
    3
    Views:
    762
    Alexey Dmitriev
    Oct 11, 2003
  3. markla
    Replies:
    1
    Views:
    522
    Steven Cheng
    Oct 6, 2008
  4. Stanimir Stamenkov
    Replies:
    5
    Views:
    2,726
    Stanimir Stamenkov
    Apr 10, 2009
  5. Replies:
    5
    Views:
    973
    Brian McCauley
    Nov 29, 2006
Loading...

Share This Page