Hi!
I would assume that the file is not validated at all. Therefore, it parses
fine. I had the same problem with getting XML and schema to work, using the
sax parser. There are a few ways to act about this:
- use an EntityResolver (doesn't work for me yet, and nobody was able to
explain why)
- tell the sax parser to use schema. This is done by setting the schema
property
- tell the sax parser, which schema to use, explizitly.
and, last but not least, use URI syntax for the schema:
file:///f:/myprojects/scrpg/scr_02.xsd
<file:///f:/myprojects/scrpg/scr_02.xsd>
The following works for me:
In the xml file, do not reference the schema file.
Use the following in your code:
...
private static final String FLAG_VALIDATE = "
http://xml.org/sax/features/validation
<http://xml.org/sax/features/validation> ";
private static final String FLAG_SCHEMA = "
http://apache.org/xml/features/validation/schema
<http://apache.org/xml/features/validation/schema> ";
private static final String FLAG_NAMESPACE = "
http://xml.org/sax/features/namespaces
<http://xml.org/sax/features/namespaces> ";
private static final String PROP_SCHEMA = "
http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
<http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation>
";
...
saxParser.getXMLReader().setFeature(FLAG_VALIDATE, validate);
if (null != schema) {
saxParser.getXMLReader().setFeature(FLAG_SCHEMA, true);
saxParser.getXMLReader().setFeature(FLAG_NAMESPACE, true);
saxParser.setProperty(PROP_SCHEMA, schema);
}
...
where 'schema' is a string, containing the URI.
The above code has one major disadvantage: setting the schema explizitly
means, that you have to know which one to use (unless you are parsing alway
the same file).
If you find out a better way, please let me know, too.
Greetings
Heiner
-----Urspr�ngliche Nachricht-----
Von: Richard Moster [mailto:[EMAIL PROTECTED]
Gesendet am: Mittwoch, 16. Oktober 2002 07:00
An: [EMAIL PROTECTED]
Betreff: [Error] :2:273: cvc-elt.1: Cannot find the declaration of element
'didl:DIDL'.
I have an XML file, referencing a schema that in turn imports another
schema. When I use the SAX2 parser to parse with validation, I'm getting
the following error:
[Error] :2:273: cvc-elt.1: Cannot find the declaration of element
'didl:DIDL'.
didl:DIDL is the root element of the XML file and is declared in the
imported schema (see below). The whole thing works just fine in XMLSpy5.
Is there a problem with the validation if the root element has a namespace
qualifier defined in the same element? The file parses fine, but I'm
getting that error message.
_____
The XML file starts off:
<?xml version="1.0" encoding="UTF-8"?>
<didl:DIDL xmlns:didl="namespace1" xmlns="namespace2" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
<http://www.w3.org/2001/XMLSchema-instance> " xsi:schemaLocation="namespace2
F:/MyProjects/SCRPG/SCR_02.xsd">
where namespace1 and namespace2 are placeholders are placeholders for the
purpose of this email--the files actually use valid namespaces.
_____
The beginning of the schema F:/MyProjects/SCRPG/SCR_02.xsd is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="namespace2" xmlns:didl="namespace1" xmlns:xs="
http://www.w3.org/2001/XMLSchema <http://www.w3.org/2001/XMLSchema> "
xmlns="namespace2" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="namespace1" schemaLocation="didl-schema-mod.xsd"/>
_____
The beginning of the imported schema didl-schema-mod.xsd is:
<?xml version="1.0">
<xsd:schema targetNamespace="namespace2" xmlns="namespace1" xmlns:xsd="
http://www.w3.org/2001/XMLSchema <http://www.w3.org/2001/XMLSchema> "
elementFormDefault="qualified" attributeFormDefault="unqualified"
version="0.01">
<xsd:attributeGroup name="ID_ATTRS">
<xsd:attribute name="id" type="xsd:ID" use="optional"/>
</xsd:attributeGroup>
<xsd:element name="DIDL">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Declarations"
minOccurs="0"/>
<xsd:choice>
<xsd:element ref="Container"/>
<xsd:element ref="Item"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
_____
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]