The moose likes XML and Related Technologies and the fly likes Regular expression for valid xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Regular expression for valid xml" Watch "Regular expression for valid xml" New topic
Author

Regular expression for valid xml

Manishkumar Modi
Greenhorn

Joined: Sep 23, 2011
Posts: 14
i am looking regular expression to check string is valid XML or not
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

You should never do this. Instead, try to parse you'r xml to tell if it's valid or not.
Manishkumar Modi
Greenhorn

Joined: Sep 23, 2011
Posts: 14
Thank you. and can we make regular expression to check string is valid XHTML or not
Manishkumar Modi
Greenhorn

Joined: Sep 23, 2011
Posts: 14
I want to check this is valid or not
String myString = "<manish><abc pqr="1234"/></manish>";
Zandis Murāns
Ranch Hand

Joined: Aug 18, 2009
Posts: 174

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2409
What you posted in neither well-formed nor valid XML.

Note that single regexps are not powerful enough to even check wellformedness of XML, much less validity (which implies the presence of some sort of schema).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Regular expression for valid xml
 
jQuery in Action, 3rd edition