wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes XML validation checks on String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML validation checks on String" Watch "XML validation checks on String" New topic
Author

XML validation checks on String

Manishkumar Modi
Greenhorn

Joined: Sep 23, 2011
Posts: 14
How do we perform XML validation checks on String. is there any method in java that can validate string
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Welcome to the Ranch

Please explain more of what you want to know.
Manishkumar Modi
Greenhorn

Joined: Sep 23, 2011
Posts: 14
Question is How do i perform XML Validation on String,
Detail : I have 1 string that contains tags, i want to check that string contains valid XML data or not...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
You need some sort of parser.
That is too difficult for "beginning", so I shall move you.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

What kind of validation? Do you mean parsing XML documents against a DTD or XSD file?

For XSD validation it's actually not that hard. You first use SchemaFactory to create a Schema.
Next you create a DocumentBuilderFactory or SAXParserFactory, set the Schema and set validating on.
Next you use the DocumentBuilderFactory to create a DocumentBuilder, or the SAXParserFactory to create a SAXParser.
Finally, you use the DocumentBuilder or SAXParser to parse the XML document.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Manishkumar Modi
Greenhorn

Joined: Sep 23, 2011
Posts: 14
Actually i want to perform xhtml validation rules on string
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
xhtml is infinitely "extensible", in essence, by the x itself so named. I suppose you don't mean you've your own custom module extending the base of it?... xhtml validation is no difference from validating any schema/DTD backed xml document and the outline of how to do it is already pointed out.

If you mean you are not yet very agile in doing validating xml, I would say you can use many validating service out there such as this or any other you might come across after by googling.
http://validator.w3.org/#validate_by_input
You can cut-and-paste the "string" for the purpose or you can use the variation of validating via a url...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

So what's the problem exactly? Do you not know how to do XML validation? Or is that you know how to do that, but not if the XML is in a String?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: XML validation checks on String
 
Similar Threads
Web Service Security - xml entity injection Attack
Struts2 Validation
Validation - best approach
jsp document
validating forms