Reputation: 3067
I m working on a project which requires to edit the xml tags via jquery. Before I save the xml in the form of string, I wanted to validate if the xml tags matched properly but on the client side with jquery. Is there any simple way to achieve this?
Thanks
Upvotes: 2
Views: 5275
Reputation: 19549
I was looking to validate a form text input as XML using the excellent jQuery Validation plugin, this ended up doing the trick:
$.validator.addMethod('XML', function(value, element){
var isXml;
if(!this.optional(element)){
try{
isXml = $.parseXML(value);
}catch(e){
isXml = false;
}
}
return isXml !== false;
}, 'This is not valid XML');
Upvotes: 4