| Author |
Solution for "cvc-elt.1: Cannot find the declaration of element xxx" in JAVA
|
i ananthaprakash
Greenhorn
Joined: Aug 31, 2011
Posts: 9
|
|
The best solution for "cvc-elt.1: Cannot find the declaration of element xxx" error is as below.
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true); //We need to make sure we add this line
We should also make sure that we add proper xmlns attribute to the root tag of the XML file.
This is the valid xml file which is validated against the given xsd file.
Eg test.xml file and test.xsd file are as below.
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<order xmlns="urn:nonstandard:test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:nonstandard:test file:test.xsd">
<user>
<fullname>Bob Jones</fullname>
<deliveryAddress>
123 This road,
That town,
Bobsville
</deliveryAddress>
</user>
<products>
<product id="12345" quantity="1" />
<product id="3232" quantity="3" />
</products>
</order>
test.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
xmlns="urn:nonstandard:test"
targetNamespace="urn:nonstandard:test">
<xsd:element name="order" type="Order" />
<xsd:complexType name="Order">
<xsd:all>
<xsd:element name="user" type="User" minOccurs="1" maxOccurs="1" />
<xsd:element name="products" type="Products" minOccurs="1" maxOccurs="1" />
</xsd:all>
</xsd:complexType>
<xsd:complexType name="User">
<xsd:all>
<xsd:element name="deliveryAddress" type="xsd:string" />
<xsd:element name="fullname">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="30" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="Products">
<xsd:sequence>
<xsd:element name="product" type="Product" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Product">
<xsd:attribute name="id" type="xsd:long" use="required" />
<xsd:attribute name="quantity" type="xsd:positiveInteger" use="required" />
</xsd:complexType>
</xsd:schema>
|
 |
 |
|
|
subject: Solution for "cvc-elt.1: Cannot find the declaration of element xxx" in JAVA
|
|
|