aspose file tools*
The moose likes XML and Related Technologies and the fly likes URGENT - Grammar in XML for Schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "URGENT - Grammar in XML for Schema" Watch "URGENT - Grammar in XML for Schema" New topic
Author

URGENT - Grammar in XML for Schema

Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
Hi Folks,
I have an XML document and its corresponding Schema. While parsing it with the SAX2 Parser, I first of all get the error message that the specified grammar-"http://www.w3.org" - is not found. Then its unable to recognise the schema specified in the XML and hence flashes the error message for each element & attribute that it must be declared.
I would be very greatful if someone could help me find a solution.
I am using Xerces and writing the application in Java.
For your reference I am giving the XML and Schema that is being used.
---------------
XML Document
---------------
<?xml version="1.0" encoding="UTF-8"?>
<Person xmlns="http://www.w3.org" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:SchemaLocation="C:\SchemaValidation\schema_test.xsd">
<RoleNo>XI-12</RoleNo>
<Age>12</Age>
</Person>
-----------------
XML Schema
-----------------
<?xml version="1.0"?>
<xsd:schema targetNamespace="http://www.w3.org" xmlns="http://www.w3.org" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
<xsd:element name="Person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RoleNo" type="xsd:string"/>
<xsd:element name="Age" type="xsd:short"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Hope for an immediate response.
Regards.

[This message has been edited by Lakshmi Ramachandran (edited June 28, 2001).]
Mahendran Duraisamy
Greenhorn

Joined: Jun 27, 2001
Posts: 7
Hi,
U sample code shows two namespace declarations why is that?
1. xmlns="http://www.w3.org"
2. xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
I believe the second one is enough to run ur application.
Try this one also,
<person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation='C:\SchemaValidation\schema_test.xsd'>

Regards,
mahendran
Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
Hi Mahendran,
Thank you for your response. I have specified two namespaces as the first one is taken as the default and the second for xsi prefix namespace. The problem "Grammar not found." is solved now as the file to recognise the grammar mentioned in the XML document while parsing was actually missing in the jar file which was in use. I am very sorry for this as I was unaware of the fact that my jar was corrupted.
Thanks for your help.
Regards,
Lakshmi

[This message has been edited by Lakshmi Ramachandran (edited July 01, 2001).]
Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
Hi Lakshmi,
I am having exactly the same problem with the schema, that is, the parser can't find the schema and I get the error "Grammar not found". Do you have both the XML doc and the schema in a jar file?
Where should I put the schema? This or similar doesn't seem to work :
<personnel xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:SchemaLocation="C:\thesis\schema\personal.xsd">
Regards,
/Manuel
[This message has been edited by Manuel Palacio (edited July 02, 2001).]


<a href="http://www.newinstance.net" target="_blank" rel="nofollow">http://www.newinstance.net</a>
Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
Hi Manuel,
Put the XML as well as the Schema in the same location as that of the application which is doing the task of parsing and validation. That works fine !
Regards.
Lakshmi

Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
Strange. I put everything in the same directory but still I get the same error: "grammar not found"
What should the xsi:SchemaLocation look like?
I am using -cp c:\jdk1.3\xerces.jar;. in the same directory where the application + the xml and xsd files are located but I get the above error.
Thanks for any tips!
Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
Now it's working. It seems that I didn't have the latest jar file.
I downloaded this file:
Xerces-J-tools.1.4.1.zip
when I should have downloaded this one:
Xerces-J-bin.1.4.1.zip
Sorry!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URGENT - Grammar in XML for Schema