Hello Deepak, when I try to use catalog.xml and catalog.xsd, i get the following errors. Can you please give me some idea on why this error could be coming:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="catalog"> <xsd:complexType> <xsd:sequence> <xsd:element ref="journal" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="title" type="xsd:string"/> <xsd:attribute name="publisher" type="xsd:string"/> </xsd:complexType> </xsd:element> <xsd:element name="journal"> <xsd:complexType> <xsd:sequence> <xsd:element ref="article" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute name="date" type="xsd:string"/> </xsd:complexType> </xsd:element> <xsd:element name="article"> <xsd:complexType> <xsd:sequence> <xsd:element name="title" type="xsd:string"/> <xsd:element ref="author" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="author" type="xsd:string"/></xsd:schema>', because
1) could not find the document;
2) the document could not be read;
3) the root element of the document is not <xsd:schema>.
Now I specified specifying noNamespaceSchemaLocation attribute. Now my xml looks like this. Both xml and xsd are WSAD workspace, so I cannot give file path. There are in the same location. So, do i need to mention any relative path?
<?xml version="1.0" encoding="utf-8" ?>
<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="catalog.xsd" >
<journal date="April 2004">
<article>
<title>Declarative Programming in Java</title>
<author>Narayanan Jayaratchagan</author>
</article>
</journal>
<journal date="January 2004">
<article>
<title>Data Binding with XMLBeans</title>
<author>Daniel Steinberg</author>
</article>
</journal>
</catalog>
Both xml and xsd are WSAD workspace, so I cannot give file path. There are in the same location. So, is there any way I can specify the path?
<?xml version="1.0" encoding="utf-8" ?>
<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="catalog.xsd" >
<journal date="April 2004">
<article>
<title>Declarative Programming in Java</title>
<author>Narayanan Jayaratchagan</author>
</article>
</journal>
<journal date="January 2004">
<article>
<title>Data Binding with XMLBeans</title>
<author>Daniel Steinberg</author>
</article>
</journal>
</catalog>
Thanks for the quick reply Deepak. I will try what you advised.
Actually, I was reading xml and xsd from file system and passing them as String. Now I am passing them as InputStream. Now I am getting these errors. Any idea?
cvc-elt.1: Cannot find the declaration of element 'catalog'.
cvc-elt.1: Cannot find the declaration of element 'journal'.
cvc-elt.1: Cannot find the declaration of element 'article'.
cvc-elt.1: Cannot find the declaration of element 'title'.
cvc-elt.1: Cannot find the declaration of element 'author'.
cvc-elt.1: Cannot find the declaration of element 'journal'.
cvc-elt.1: Cannot find the declaration of element 'article'.
cvc-elt.1: Cannot find the declaration of element 'title'.
cvc-elt.1: Cannot find the declaration of element 'author'.
XML Document has Error:true cvc-elt.1: Cannot find the declaration of element 'author'.
Please specify schema in XML document withn noNamespaceSchemaLocation attribute.