Skip to content

Instantly share code, notes, and snippets.

@bittersweetryan
Created August 3, 2011 12:41
Show Gist options
  • Save bittersweetryan/1122542 to your computer and use it in GitHub Desktop.
Save bittersweetryan/1122542 to your computer and use it in GitHub Desktop.
Validating XML
<!--- Tests --->
<cffunction name="testValidateValidXMLReturnsTrue" returntype="void" access="public" output="false" hint="I validate XML" >
<cfscript>
var expected = true;
var actual = "";
var content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><b>Hello World</b></en-note>';
var note = mock("com.714studios.cfevernote.Note","typeSafe");
note.getContent().returns(content);
makePublic(variables.cfEvernote,"validateENML");
actual = variables.cfEvernote.validateENML(note);
assertEquals(expected,actual);
</cfscript>
</cffunction>
<cffunction name="testValidateInValidXMLReturnsFalse" returntype="void" access="public" output="false" hint="I validate XML" >
<cfscript>
var expected = false;
var actual = "";
var content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><blink>Hello World</blink></en-note>';
var note = mock("com.714studios.cfevernote.Note","typeSafe");
note.getContent().returns(content);
makePublic(variables.cfEvernote,"validateENML");
actual = variables.cfEvernote.validateENML(note);
assertEquals(expected,actual);
</cfscript>
</cffunction>
<!--- Implementation Code --->
<cffunction name="validateENML" returntype="boolean" access="private" output="false" hint="I validate a notes enml against the evernote dtd" >
<cfargument name="note" type="com.714studios.cfevernote.Note" required="true" />
<cfscript>
var result = xmlValidate(arguments.note.getContent());
return result.status;
</cfscript>
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment