File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Validating String aginst schema directly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply locked New topic

Validating String aginst schema directly

James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
Hi All,

Is there any way by which I can validate a string against xmlSchema in java?

eg. String is Audi

xmlSchema is
Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 118
There are two commonly used xml parsers in Java namely SAX and Dom.
Get more information on them by doing Google search and use the parser which meets your requirements.

Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
Rob Spoor

Joined: Oct 27, 2005
Posts: 20273

DocumentBuilderFactory and SAXParserFactory have one method you will be interested in: setSchema. You can create a Schema using SchemaFactory.

Moving to XML.

How To Ask Questions How To Answer Questions
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

You could wrap the string in some text which makes it into an XML document which you can then validate against the schema. But isn't this the same question as in your other post? I'm going to close this one as a duplicate.
I agree. Here's the link:
subject: Validating String aginst schema directly
It's not a secret anymore!