• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Validating XML

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Here this might help.

- m
 
MRaj Raj
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic