File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating XML

 
MRaj Raj
Greenhorn
Posts: 6
  • 0
  • 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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here this might help.

- m
 
MRaj Raj
Greenhorn
Posts: 6
  • 0
  • 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
  • 0
  • 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
 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • 0
  • 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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic