• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Validating Error - Help

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to fix this for last 2 days ..

I am trying to validate the XML in SAX parser and i am getting
"java.lang.ClassCastException: " error.

I am pasting the code i have and the sample XML. If some one faced the same kind of problem please share the thoughts
thanks in advance.

I am sending the XML from the command prompt

This is the code i have

class XMLBean {

public void onMessage (String uri) {

Object [] schemas = new Object[] { "C:/Murugaraj/Projects/Atlys-interface/XSD/Schemas/Common/Types/Public/rDataModel.xsd",
"C:/raj/Projects/Atlys-interface/XSD/Schemas/Atlas/jms/Public/SubscriberNotification.xsd",
"C:/raj/Projects/Atlys-interface/XSD/Schemas/Atlas/Container/Public/SubscriberNotification.xsd",
"C:/raj/Projects/Atlys-interface/XSD/Schemas/Atlas/Container/Public/MessageHeader.xsd"};

System.out.println("Parsing XML File: " + uri + "\n\n");


// The SAX handler Events are in RequestHandler which is extends from Defaulthandler

RequestHandler rh = new RequestHandler();

try {

String txt = uri;
System.out.println(txt);
SAXParserFactory fact = SAXParserFactory.newInstance();

fact.setNamespaceAware(true);
fact.setValidating(true);
fact.setFeature("http://xml.org/sax/features/validation", true);
fact.setFeature("http://apache.org/xml/features/validation/schema",true);
fact.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

SAXParser sp = fact.newSAXParser();
sp.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemas);

InputSource inSource = new InputSource(new FileInputStream(txt));
sp.parse(inSource, rh);

}catch(SAXNotRecognizedException x){
System.out.println(" SAXNotRecognizedException Parsing error" );
x.getMessage();
}catch(SAXParseException spe){
System.out.println("\n** Parsing error SAXParseException" + ", line " + spe.getLineNumber() + ", uri " + spe.getSystemId());
System.out.println(" " + spe.getMessage());
Exception x = spe;
if (spe.getException() != null)
x = spe.getException();
x.printStackTrace();
}catch(SAXException sxe){
System.out.println(" SAXException Parsing error" );
Exception x = sxe;
if(sxe.getException() != null)
x=sxe.getException();
x.printStackTrace();
}catch (IOException ioe) {
System.out.println(" IOException Parsing error" );
ioe.printStackTrace();
}catch (Throwable t){
t.printStackTrace();
} // End of catch
} // End of onMessage

public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Usage: java SAXParserDemo [XML URI]");
System.exit(0);
}

String uri = args[0];
XMLBean call = new XMLBean ();
call.onMessage(uri);
} // End of main
} // End of XMLBean


This is the error i am getting

java.lang.ClassCastException: [Ljava.lang.Object;
at weblogic.apache.xerces.impl.xs.XMLSchemaValidator.reset(Lweblogic/apa
che/xerces/xni/parser/XMLComponentManager V(XMLSchemaValidator.java:1374)
at weblogic.apache.xerces.parsers.BasicParserConfiguration.reset()V(Basi
cParserConfiguration.java:523)
at weblogic.apache.xerces.parsers.DTDConfiguration.reset()V(DTDConfigura
tion.java:624)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(Z)Z(DTDConfigur
ation.java:498)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(Lweblogic/apach
e/xerces/xni/parser/XMLInputSource V(DTDConfiguration.java:581)
at weblogic.apache.xerces.parsers.XMLParser.parse(Lweblogic/apache/xerce
s/xni/parser/XMLInputSource V(XMLParser.java:152)
at weblogic.apache.xerces.parsers.AbstractSAXParser.parse(Lorg/xml/sax/I
nputSource V(AbstractSAXParser.java:1175)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(Lorg/xml/sax/InputSource V
(WebLogicXMLReader.java:135)
at weblogic.xml.jaxp.RegistryXMLReader.parse(Lorg/xml/sax/InputSource V
(RegistryXMLReader.java:152)
at javax.xml.parsers.SAXParser.parse(Lorg/xml/sax/InputSource;Lorg/xml/s
ax/helpers/DefaultHandler V(SAXParser.java:345)
at XMLBean.onMessage(Ljava/lang/String V(XMLBean.java:80)
at XMLBean.main([Ljava/lang/String V(XMLBean.java:130)


The Sample XML looks like this

<?xml version="1.0" encoding="UTF-8" ?>
- <SubscriberNotification xmlns:cng="http://csi.test.com/CSI/Namespaces/Types/Public/DataModel.xsd" xmlns="http://csi.test.com/ATLAS/Namespaces /Container/JMS/SubscriberNotification.xsd" xmlns:sn="http://csi.test.com/ATLAS/Namespaces/Container/Public/SubscriberNotification.xsd" xmlns:mh="http://csi.test.com/ATLAS/Namespaces/Container/Public/MessageHeader.xsd">
- <mh:MessageHeader>
- <mh:TrackingMessageHeader>
<cng:version>v3</cng:version>
<cng:messageId>08001200312101117273772521</cng:messageId>
<cng riginatorId>CARE</cng riginatorId>
<cng ateTimeStamp>2005-08-23T13:45:57Z</cng ateTimeStamp>
</mh:TrackingMessageHeader>
- <mh:SequenceMessageHeader>
<cng:sequenceNumber>1</cng:sequenceNumber>
<cng:totalInSequence>1</cng:totalInSequence>
</mh:SequenceMessageHeader>
</mh:MessageHeader>
- <sn:SubscriberNotification>
<sn:billingSystemEventGenrationDateTime>2003-12-10T11:17:27.377Z</sn:billingSystemEventGenrationDateTime>
<sn:notificationType>UpdateSubscriberStatusNotification</sn:notificationType>
<sn:notificationSubType>3400</sn:notificationSubType>
- <sn:Account>
- <sn:billingMarket>
<sn:billingMarket>08</sn:billingMarket>
</sn:billingMarket>
<sn:billingSystemId>CARE</sn:billingSystemId>
</sn:Account>
</sn:SubscriberNotification>
</SubscriberNotification>
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Object [] schemas = new Object[] { "C:/Murugaraj/Projects/Atlys-interface/XSD/Schemas/Common/Types/Public/rDataModel.xsd",
"C:/raj/Projects/Atlys-interface/XSD/Schemas/Atlas/jms/Public/SubscriberNotification.xsd",
"C:/raj/Projects/Atlys-interface/XSD/Schemas/Atlas/Container/Public/SubscriberNotification.xsd",
"C:/raj/Projects/Atlys-interface/XSD/Schemas/Atlas/Container/Public/MessageHeader.xsd"};



schemas has to be of type String representing a URL not an Object array. AFAIK it is not possible to validate against multiple schemas

I think 1 schema can import another

-Raj
 
MRaj Raj
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks

You are totally correct and i agree with you.

I was looking into this forum y'day

http://forum.java.sun.com/thread.jspa?threadID=266055&tstart=105

seems like i can pass array of objects so then i decided to pass multiple schemas. Also there is one sun website claims validating multiple schemas

Yes, i want to validate with more than one schema .. 'cos my XML generated based on 4 schemas ( xsd's)

I did not get what you mean by "import" dependand schemas..

import the depandant schema on the "parent schema" thats what you meant ?

Thanks a lot ...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic