Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to related xml file to schema

Status
Not open for further replies.

ShubhaMishra

Programmer
Jan 4, 2007
10
IN
Hi ,
I have creating an xml document from a string and I have to validate that against xml schema. Here is the code

String == <MessageRequest><Client>test</Client><Service>caller</Service</MessageRequest>

Schema :

<?xml version="1.0"?>
<xsd:schema xmlns:xsd=" targetNamespace="" xmlns=" elementFormDefault="qualified">
<xsd:element name="MessageRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Client" type="xsd:string"/>
<xsd:element name="Service" type="xsd:string" use="required"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

And when I try to vailidate it using java code
Java Code:-

StringReader xmlDataReader = new StringReader(xmlData.toString());
SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setProperty("// get root element after building document.
Document xmlDocument = builder.build(xmlDataReader);

I am receiving following error :-org.jdom.input.JDOMParseException: Error on line 1: Document is invalid: no grammar found.

Can anybody help me on this.

Thanks in Advance,
Shubhangi
 
Hi Dian,
Thanks for this link, but in my case if i was using
builder.setProperty("
it was giving the following error
org.jdom.input.JDOMParseException: Error on line 1: cvc-elt.1: Cannot find the declaration of element 'MessageRequest'.

I had change my code as following after that it start working Java Code

StringReader xmlDataReader = new StringReader(xmlData.toString());
SAXBuilder builder = new SAXBuilder();
builder.setValidation(true);
builder.setFeature(" builder.setProperty("

Thanks
Hope this can help anybidy else in future :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top