This discussion is archived
1 Reply Latest reply: Oct 18, 2012 1:47 AM by 801521 RSS

org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of el

801521 Newbie
Currently Being Moderated
Hi ,
I am facing below error at run-time while trying to validate generated xml message with the xsd file

Error:
=====================

2012-10-16 22:26:10.020 [64095186 main] [TIBCO EMS]: [J] [SSL] selected cipher: SSL_RSA_WITH_RC4_128_MD5
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ClearingSwitchAcknowledgement'.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.XMLSchemaValidator.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Unknown Source)
at com.citi.cs.tibco.CSTibcoNeftAckSender.validateXSD(CSTibcoNeftAckSender.java:845)
at com.citi.cs.tibco.CSTibcoNeftAckSender.validateXML(CSTibcoNeftAckSender.java:810)
at com.citi.cs.tibco.CSTibcoNeftAckSender.sendMessage(CSTibcoNeftAckSender.java:219)
at com.citi.cs.tibco.CSTibcoNeftAckSender.run(CSTibcoNeftAckSender.java:332)
at java.lang.Thread.run(Thread.java:811)
java.lang.Exception: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ClearingSwitchAcknowledgement'.
at com.citi.cs.tibco.CSTibcoNeftAckSender.validateXSD(CSTibcoNeftAckSender.java:856)
at com.citi.cs.tibco.CSTibcoNeftAckSender.validateXML(CSTibcoNeftAckSender.java:810)


===========================================




XML message:
=========
Sent message 'TextMessage={ Header={ JMSMessageID={ID:ccdcsh1_csh_ap_ems2_steesb_ap_dev.3EE5506C356241EA:4} JMSDestination={Queue[citi.cmb.ap.concorde_159767
.q.ft.cssack.inward]} JMSReplyTo={null} JMSDeliveryMode={PERSISTENT} JMSRedelivered={false} JMSCorrelationID={null} JMSType={null} JMSTimestamp={Tue Oct 16 1
6:34:21 GMT+08:00 2012} JMSExpiration={0} JMSPriority={4} } Properties={ } Text={<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ClearingSwitchAcknowledgement xmlns:ns2="http://www.citi.com/gts/concorde/clearingswitch/clearingswitchschema">
<TxnRefNum>AFAAAAAsdf7BBBBBCAABAAAAAAAAA023</TxnRefNum>
<AckLevel>001</AckLevel>
<ReasonCode></ReasonCode>
<ReasonDescription></ReasonDescription>
<BranchCode>952</BranchCode>
<UTRNumber>CITIN12001925359</UTRNumber>
<SubStatusCode></SubStatusCode>
<CreditDateTime>2012-10-16T16:34:21 GMT+08:00</CreditDateTime>
<Reserved1></Reserved1>
<Reserved2></Reserved2>
<Reserved3></Reserved3>
</ClearingSwitchAcknowledgement>
} }'




XSD File:
=======

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.citi.com/gts/concorde/common/cstibcoackmsg" targetNamespace="http://www.citi.com/gts/concorde/common/cstibcoackmsg" elementFormDefault="qualified" attributeFormDefault="unqualified">
          <xs:element name="ClearingSwitchAcknowledgement">
     <xs:complexType>
                    <xs:sequence>
                         <xs:element name="TxnRefNum" type="xs:string" minOccurs="0"/>
                         <xs:element name="AckLevel" type="xs:string" minOccurs="0"/>
                         <xs:element name="ReasonCode" type="xs:string" minOccurs="0"/>
                         <xs:element name="ReasonDescription" type="xs:string" minOccurs="0"/>
                         <xs:element name="BranchCode" type="xs:string" minOccurs="0"/>
                         <xs:element name="UTRNumber" type="xs:string" minOccurs="0"/>
                         <xs:element name="SubStatusCode" type="xs:string" minOccurs="0"/>
                         <xs:element name="CreditDateTime" type="xs:dateTime" minOccurs="0"/>
                         <xs:element name="Reserved1" type="xs:string" minOccurs="0"/>
                         <xs:element name="Reserved2" type="xs:string" minOccurs="0"/>
                         <xs:element name="Reserved3" type="xs:string" minOccurs="0"/>
                    </xs:sequence>
               </xs:complexType>
          </xs:element>               
</xs:schema>



Code:
*=====*

*public void validateXSD(String s, String s1) throws Exception {*
*try {*
*//SchemaFactory schemafactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");*
SchemaFactory schemafactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

File file = new File(s);
*if (file != null && file.exists()) {*
Schema schema = schemafactory.newSchema(file);

Validator validator = schema.newValidator();

DocumentBuilderFactory documentbuilderfactory = DocumentBuilderFactory.newInstance();
documentbuilderfactory.setValidating(false);
*// documentbuilderfactory.setValidating(true);*
documentbuilderfactory.setNamespaceAware(true);


DocumentBuilder documentbuilder = documentbuilderfactory.newDocumentBuilder();

Document document = documentbuilder.parse(new InputSource(new StringReader(s1)));

validator.validate(new DOMSource(document));
System.out.println("validated sucessfully");

*} else {*
throw new Exception((new StringBuilder()).append("XSD File <").append(s).append("> doesnt exist").toString());
*}*
*}*
*catch (Exception exception) {*
System.out.println((new StringBuilder()).append("Got Exception in Resource Bundle/Properties : ").append(exception.getMessage()).toString());

exception.printStackTrace();
throw new Exception(exception);
*}*
*}*



=========================


In the above code 1st parameter we are passing is "xsd" file and 2nd parameter is "xml message generated"
Have tried with documentbuilderfactory.setValidating(true); and documentbuilderfactory.setValidating(false);
But still getting same error for long time now.


=========================

please note below generate function as well using which I am generating xml message n passing it to validateXSD function


*private String generateMessage(CSTibcoAckMsgType CSTibcoAckMsg, String pkg)  {*

JAXBContext jaxbContext = null;
Marshaller marshaller = null;
StringWriter xmlWriter = null;
PrintWriter writer = null;
String xmlMessage = null;

*try {*


jaxbContext = JAXBContext.newInstance(pkg);
marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

xmlWriter = new StringWriter();
writer = new PrintWriter(xmlWriter);
marshaller.marshal(CSTibcoAckMsg, writer);
xmlMessage = xmlWriter.toString();

*//System.out.println("{Process} - Generated msg for package :> " + pkg);*
*//System.out.println("{Process} - Generated msg for package :> " +xmlMessage);*
*} catch (JAXBException e) {*

*System.out.println( "{Process} - JAXBException occurred while generating PP messages ");*
*e.printStackTrace();*


*} catch (Exception e) {*

*System.out.println("{Process} - Exception occurred while generating PP messages ");*
*e.printStackTrace();*

*}*

*return xmlMessage;*
*}*

=========================

Please let me know how to resolve this error


Thanks & Regards,
Harish

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points