Created
January 4, 2012 16:45
-
-
Save folkengine/1560888 to your computer and use it in GitHub Desktop.
Grails XML Parsing By ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.ApplicationContextAware; | |
class XMLExample implements ApplicationContextAware { | |
def applicationContext | |
/** | |
* <?xml version="1.0" encoding="UTF-8"?> | |
* <elementNames> | |
* <elementName id="UniqueIDInXMLFile" bar="baz" /> | |
* <elementName id="AnotherUniqueIDInXMLFile" bar="baz" /> | |
* </elementNames> | |
* | |
* @return | |
*/ | |
def getXMLElement() { | |
def myfile = applicationContext.getResource("/WEB-INF/xml/file.xml").getFile() | |
// groovy.util.slurpersupport.GPathResult | |
def res = XML.parse(myfile.text) | |
def myElement = res.elementName.find { it.@id == "UniqueIDInXMLFile" } | |
def foo | |
foo.bar = [email protected]() | |
if ([email protected]() == "true") { | |
foo.bool = true | |
} else { | |
foo.bool = false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment