This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in schema validation  RSS feed

 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I am trying to validate xml string against the schema but i am getting a exception. Can anybody tell me what's wrong.

XML String
***********
pStrXMLSring =
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns1:correspondence-message-response xmlns:ns1="http://www.insystems.com/correspondence12"><ns1:response id="100_200_C"><ns1:success><ns1:letter-generation-response letter-id="591610101010103810"></ns1:letter-generation-response><ns1:warnings><ns1:corr-warning code="compNotEff" description="Letter Component 'Not Effective Component' has invalid effective date range and is not included within generated letter"></ns1:corr-warning><ns1:corr-warning code="addinNotEff" description="Attachment 'Not Effective Addin' has invalid effective date range and is not included within generated letter"></ns1:corr-warning></ns1:warnings></ns1:success></ns1:response><ns1:response id="100_200_B"><ns1:failure><ns1:errors><ns1:error code="compNotEff" description="Letter Component 'Not Effective Component' has invalid effective date range and is not included within generated letter"></ns1:error><ns1:error code="compNotEff" description="Letter Component 'Not Effective Component' has invalid effective date range and is not included within generated letter"></ns1:error></ns1:errors></ns1:failure></ns1:response></ns1:correspondence-message-response>

Validation code
try
{
SAXParserFactory saxfact = SAXParserFactory.newInstance();
saxfact.setNamespaceAware(true);
//saxfact.setValidating(true);
SAXParser parser = saxfact.newSAXParser() ;

XMLReader reader = parser.getXMLReader();
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setFeature("http://apache.org/xml/features/validation/schema",true);
//reader.setFeature ("http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", true);
reader.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "CorrespondenceMessageResponse.xsd");

parser.parse(new InputSource(new StringReader(pStrXMLSring)),this);
}
catch (Exception saxe)
{
Renewalog.warn(saxe.getMessage());
}

Exception
*****************
cvc-elt.1: Cannot find the declaration of element 'ns1:correspondence-message-response'.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!