This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML validation checks on String

 
Manishkumar Modi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we perform XML validation checks on String. is there any method in java that can validate string
 
Campbell Ritchie
Sheriff
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please explain more of what you want to know.
 
Manishkumar Modi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need some sort of parser.
That is too difficult for "beginning", so I shall move you.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Manishkumar Modi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i want to perform xhtml validation rules on string
 
g tsuji
Ranch Hand
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic