• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Validating XML

 
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 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
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here this might help.

- m
 
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 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
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking for an example too...please update the FAQs with validating with SAX.
[ February 22, 2006: Message edited by: Mohan Panigrahi ]
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic