Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@loadster
Last active October 14, 2015 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loadster/9994bd480d0cce821c17 to your computer and use it in GitHub Desktop.
Save loadster/9994bd480d0cce821c17 to your computer and use it in GitHub Desktop.
Validate a property in an XML document with JavaScript
// <cars>
// <car id="13"><make>Volkswagen</make><model>Thing</model></car>
// <car id="80"><make>Land Rover</make><model>Series IIA</model></car>
// </cars>
function capture(response) {
var xml = XML.parse(response.bodyAsString);
var cars = xml.childNamed('cars');
return cars && cars.childrenNamed('car').length > 0; // Validation is successful if there was at least 1 car
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment