| Author |
Validating XML
|
MRaj Raj
Greenhorn
Joined: Feb 14, 2006
Posts: 6
|
|
Hi i am new to java & XML & SAX Parser.. i need Urgent Help How should i validate the XML. I have a XSD (schema ) and i am using the SAX parser. Please some one point me a good link or sample code to validate the XML against the XSD. The following is the portion of code written to call the SAX parser ---- RequestHandler rh = new RequestHandler(); -> I mentioned this class below TextMessage textMessage = (TextMessage) msg; --> "msg" has XML file String txt = textMessage.getText(); try { SAXParserFactory fact = SAXParserFactory.newInstance(); SAXParser sp = fact.newSAXParser(); InputSource inSource = new InputSource(); inSource.setCharacterStream(new StringReader(txt)); sp.parse(inSource, rh); } -- The following class i am using to parse the XML .. this has all methods like startDocument,startElelment,endElelment,characters .. etc., etc., etc., public class RequestHandler extends DefaultHandler { } -- Please some one let me know how to validate .. i have XSD's which was given by another team .. i do not know how to validate XML against XSD (schema) using SAX parser
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Here this might help. - m
|
Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
|
 |
MRaj Raj
Greenhorn
Joined: Feb 14, 2006
Posts: 6
|
|
Thanks Madav http://faq.javaranch.com/view?HowToValidateXmlAgainstAnySchema I am looking into this link .. seems like this will work for DOM. I am using SAX parser .. does it work for SAX parser too ? Please let me know -Thanks
|
 |
Madhav Lakkapragada
Ranch Hand
Joined: Jun 03, 2000
Posts: 5040
|
|
Never thought of it nor did I ever try. Did you give it a try ? Do let us know so that we can update the FAQ accordingly. - m
|
 |
Mohan Panigrahi
Ranch Hand
Joined: Sep 28, 2001
Posts: 142
|
|
I am looking for an example too...please update the FAQs with validating with SAX. [ February 22, 2006: Message edited by: Mohan Panigrahi ]
|
 |
 |
|
|
subject: Validating XML
|
|
|