Query regarding Catalog resolver 'cvc-elt.1: Cannot find thedeclaration of element'

A

Amit Jain

Hi All,
I am trying to configure catalog resolver api in my project.
But getting exception as mention below:

************************ Exception Start ***********************
org.jdom.input.JDOMParseException: Error on line 2 of document
file:///C://Workspace//catalogresolver//classes//note.xml: cvc-elt.1:
Cannot find the declaration of element 'note'.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:465)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:891)
at TestResolver.main(TestResolver.java:41)
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the
declaration of element 'note'.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException
(ErrorHandlerWrapper.java:236)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error
(ErrorHandlerWrapper.java:172)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError
(XMLErrorReporter.java:382)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError
(XMLErrorReporter.java:316)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement
(XMLSchemaValidator.java:1944)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement
(XMLSchemaValidator.java:705)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement
(XMLNSDocumentScannerImpl.java:330)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl
$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:
779)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl
$FragmentContentDispatcher.dispatch
(XMLDocumentFragmentScannerImpl.java:1794)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse
(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse
(AbstractSAXParser.java:1242)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
... 2 more
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the
declaration of element 'note'.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException
(ErrorHandlerWrapper.java:236)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error
(ErrorHandlerWrapper.java:172)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError
(XMLErrorReporter.java:382)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError
(XMLErrorReporter.java:316)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement
(XMLSchemaValidator.java:1944)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement
(XMLSchemaValidator.java:705)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement
(XMLNSDocumentScannerImpl.java:330)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl
$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:
779)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl
$FragmentContentDispatcher.dispatch
(XMLDocumentFragmentScannerImpl.java:1794)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse
(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse
(AbstractSAXParser.java:1242)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:891)
at TestResolver.main(TestResolver.java:41)
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the
declaration of element 'note'.
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException
(ErrorHandlerWrapper.java:236)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error
(ErrorHandlerWrapper.java:172)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError
(XMLErrorReporter.java:382)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError
(XMLErrorReporter.java:316)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement
(XMLSchemaValidator.java:1944)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement
(XMLSchemaValidator.java:705)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement
(XMLNSDocumentScannerImpl.java:330)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl
$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:
779)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl
$FragmentContentDispatcher.dispatch
(XMLDocumentFragmentScannerImpl.java:1794)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument
(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse
(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse
(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse
(AbstractSAXParser.java:1242)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:891)
at TestResolver.main(TestResolver.java:41)
************************ Exception End ***********************

************************ Java Code Start ***********************
import org.apache.xml.resolver.tools.CatalogResolver;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
public class TestResolver {
public static void main(String[] args) throws Exception{
CatalogResolver cr = new CatalogResolver();
SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://apache.org/xml/features/validation/
schema", true);
builder.setFeature("http://xml.org/sax/features/namespaces",
true);
builder.setEntityResolver(cr);
String name = "http://apache.org/xml/properties/schema/
external-schemaLocation";
String value = "http://schemas.xml.org/abc/123/";
builder.setProperty(name, value);
try{
Document doc = builder.build("C://Workspace//
catalogresolver//classes//note.xml");
}catch(Exception e){
e.printStackTrace();
}
}
************************ Java Code End ***********************

************************ CatalogManager.properties Start
***********************
catalogs=corecatalog.xml;
relative-catalogs=false
static-catalog=yes
catalog-class-name=org.apache.xml.resolver.Resolver
verbosity=1
************************ CatalogManager.properties End
***********************

************************ corecatalog.xml Start
***********************
<catalog xmlns="urn:eek:asis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://schemas.xmlsoap.org/soap/envelope/"
uri="note.xsd"/>
</catalog>
************************ corecatalog.xml End
***********************

************************ note.xml Start ***********************
<?xml version="1.0"?>
<note xmlns="http://schemas.xml.org/abc/123/">
<to>Amit</to>
<from>Jain</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
************************ note.xml End ***********************

************************ note.xsd Start ***********************
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xml.org/abc/123/"
targetNamespace="http://schemas.xml.org/abc/123/">

<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
************************ note.xsd End ***********************

I took reference from below mentioned URL's:
- http://www.sagehill.net/docbookxsl/UseCatalog.html
- http://xerces.apache.org/xerces2-j/faq-xcatalogs.html

If I missed something which need to be added to dig into issue. please
let me know...

Thanks in advance.

Thanks & regards,
Amit Jain
 
A

Arne Vajhøj

Amit said:
I am trying to configure catalog resolver api in my project.
But getting exception as mention below:

************************ Exception Start ***********************
org.jdom.input.JDOMParseException: Error on line 2 of document
file:///C://Workspace//catalogresolver//classes//note.xml: cvc-elt.1:
Cannot find the declaration of element 'note'.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:465)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:891)
at TestResolver.main(TestResolver.java:41)
public static void main(String[] args) throws Exception{
CatalogResolver cr = new CatalogResolver();
SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setFeature("http://xml.org/sax/features/namespaces", true);
builder.setEntityResolver(cr);
String name = "http://apache.org/xml/properties/schema/external-schemaLocation";
String value = "http://schemas.xml.org/abc/123/";
builder.setProperty(name, value);
try{
Document doc = builder.build("C://Workspace//catalogresolver//classes//note.xml");

I am extremely skeptical about // here !
}catch(Exception e){
e.printStackTrace();
}
}
<?xml version="1.0"?>
<note xmlns="http://schemas.xml.org/abc/123/">
<to>Amit</to>
<from>Jain</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xml.org/abc/123/"
targetNamespace="http://schemas.xml.org/abc/123/">

<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
If I missed something which need to be added to dig into issue. please
let me know...

This following code works here:

import org.jdom.input.SAXBuilder;
import org.jdom.Document;

public class Note {
static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";
static final String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
public static void main(String[] args) throws Exception{
SAXBuilder builder = new SAXBuilder();
builder.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
builder.setProperty(JAXP_SCHEMA_SOURCE, "C:/note.xsd");
try{
Document doc = builder.build("C:/note.xml");
}catch(Exception e){
e.printStackTrace();
}
}
}

Arne
 
A

Amit Jain

Hi Arne,
Thanks for your input,

I don't want to provide xsd name in java code.
/****
builder.setProperty(JAXP_SCHEMA_SOURCE, "C:/note.xsd");
****/

=>For this purpose I configured the Catalog Resolver.
******* corecatalog.xml Starts *******
<catalog
xmlns="urn:eek:asis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://schemas.xmlsoap.org/soap/
envelope/"
uri="note.xsd"/>
</catalog>
******* corecatalog.xml End *******


I am getting problem while using Catalog resolver. Please have a look
on below mentioned links.
-> http://xml.apache.org/commons/components/resolver/resolver-article.html
-> http://xml.apache.org/commons/components/resolver/

Thanks & regards,
Amit Jain
 
A

Aakansha

Hi All,

I am also struggling with same problem.
Please help.

Thanks & regards,
Aakansha
 
A

Arne Vajhøj

Amit said:
I don't want to provide xsd name in java code.
/****
builder.setProperty(JAXP_SCHEMA_SOURCE, "C:/note.xsd");
****/

=>For this purpose I configured the Catalog Resolver.
******* corecatalog.xml Starts *******
<catalog
xmlns="urn:eek:asis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://schemas.xmlsoap.org/soap/
envelope/"
uri="note.xsd"/>
</catalog>
******* corecatalog.xml End *******


I am getting problem while using Catalog resolver. Please have a look
on below mentioned links.
-> http://xml.apache.org/commons/components/resolver/resolver-article.html
-> http://xml.apache.org/commons/components/resolver/

The code can easily be modified to do that.

mport org.jdom.input.SAXBuilder;
import org.jdom.Document;

import com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver;

public class Note2 {
static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";
static final String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
public static void main(String[] args) throws Exception{
SAXBuilder builder = new SAXBuilder();
builder.setValidation(true);
builder.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
//builder.setProperty(JAXP_SCHEMA_SOURCE, "C:/note.xsd");
System.setProperty("xml.catalog.files", "C:/corecatalog.xml");
builder.setEntityResolver(new CatalogResolver());
try{
Document doc = builder.build("C:/note.xml");
}catch(Exception e){
e.printStackTrace();
}
}
}

But you need to:

1) fix the XML so it refer to the schema

<?xml version="1.0"?>
<note xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.xml.org/abc/123/"
xsi:schemaLocation="http://schemas.xml.org/abc/123/
http://schemas.xml.org/abc/123/">
<to>Amit</to>
<from>Jain</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

2) fix the catalog so it specify the correct namespace

<catalog xmlns="urn:eek:asis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://schemas.xml.org/abc/123/"
uri="file:///C:/note.xsd"/>
</catalog>

3) fix the schema so the XML is valid for the schema

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xml.org/abc/123/"
elementFormDefault="qualified"
targetNamespace="http://schemas.xml.org/abc/123/">

<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Arne
 
A

Arne Vajhøj

Aakansha said:
I am also struggling with same problem.

Well - I answered the question.

But if you start from scratch, then you should not have
problems getting it to work.

Arne
 
A

Amit Jain

Hi Arne,

Thank you very much.

I was also suspecting there might be some problem with xml and xsd.

Could you please suggest what changes are need in xml and xsd to make
it workable.

Thanks once again.

Amit Jain
 
A

Amit Jain

Hi Arne,

I belive its not good to ask you each and every thing. But it will be
great for me if you give me your inputs for xml and xsd.

Thanks & regards,
Amit Jain
 
A

Arne Vajhøj

Amit said:
I was also suspecting there might be some problem with xml and xsd.

Could you please suggest what changes are need in xml and xsd to make
it workable.

I did post the modified Java, XML, Schema and catalog.

Arne
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top