ShubhaMishra
Programmer
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
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