You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Amthauer, Heiner" <He...@t-systems.com> on 2002/10/16 08:51:46 UTC

AW: [Error] :2:273: cvc-elt.1: Cannot find the declaration of ele ment 'didl:DIDL'.

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:richard@moster.net]
Gesendet am: Mittwoch, 16. Oktober 2002 07:00
An: xerces-j-user@xml.apache.org
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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


RE: [Error] :2:273: cvc-elt.1: Cannot find the declaration of element 'didl:DIDL'.

Posted by Richard Moster <ri...@moster.net>.
I tried using an EntityResolver--it's called, but the error

	[Error] :2:273: cvc-elt.1: Cannot find the declaration of element
'didl:DIDL'.

is encountered even BEFORE my EntityResolver returns.

I'm think the problem is with imported schemas.  The following directly
declares the root element and does NOT generate an error:

------------------------------------------ EXAMPLE
1 --------------------------------------------------------------
rootTest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<f:root xsi:schemaLocation="http://simple F:/MyProjects/SCRPG/rootTest.xsd"
xmlns:f="http://simple" xmlns="http://simple"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	TEST
</f:root>

F:/MyProjects/SCRPG/rootTest.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://simple" xmlns="http://simple"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="root" type="xs:string"/>
</xs:schema>
----------------------------------------------------------------------------
---------------------------------------

------------------------------------------ EXAMPLE
2 --------------------------------------------------------------
However, if I put the definition of element 'root' into a second schema and
import it into the first schema, it doesn't work:
----------------------------------------------------------------------------
---------------------------------------
rootTest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<f:root xsi:schemaLocation="http://simple  F:/MyProjects/SCRPG/rootTest.xsd"
xmlns:f="http://imported" xmlns="http://simple"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	TEST
</f:root>

F:/MyProjects/SCRPG/rootTest.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://simple" xmlns="http://simple"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:import namespace="http://imported"
schemaLocation="F:/MyProjects/SCRPG/rootTest2.xsd"/>
</xs:schema>

F:/MyProjects/SCRPG/rootTest2.xsd:

<?xml version="1.0"?>
<xs:schema targetNamespace="http://imported" xmlns="http://imported"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
		<xs:element name="root" type="xs:string"/>
</xs:schema>
----------------------------------------------------------------------------
-------------------------------------------
The above files validate fine in XMLSpy, but I get the error:

[Error] :2:181: cvc-elt.1: Cannot find the declaration of element 'f:root'.

using "org.apache.xerces.parsers.SAXParser".  And my EntityResolver isn't
called at all, so I presume the files are being located OK.



-----Original Message-----
From: Amthauer, Heiner [mailto:Heiner.Amthauer@t-systems.com]
Sent: Tuesday, October 15, 2002 11:52 PM
To: 'xerces-j-user@xml.apache.org'
Subject: AW: [Error] :2:273: cvc-elt.1: Cannot find the declaration of
element 'didl:DIDL'.


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:richard@moster.net]
Gesendet am: Mittwoch, 16. Oktober 2002 07:00
An: xerces-j-user@xml.apache.org
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: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org