Created
November 15, 2013 02:52
-
-
Save bmakarand2009/7478354 to your computer and use it in GitHub Desktop.
parse xml file
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
private def parseXmlClosure = { pRoot,parentObj,user,curId -> | |
def xmlMap=[:] | |
def rootName = pRoot.name() | |
def domainClz = SingUtils.DOMAIN_OBJECTS_MAP."${rootName}" | |
log.debug "domainc lass loaded as ${domainClz}" | |
def curObj=null | |
if(curId) { | |
curObj = domainClz.get(curId) | |
} | |
def xmlElementsMap = domainClz.XML_ELEMENT_MAP | |
xmlElementsMap.each{k,v-> | |
def childElem = pRoot."$k"[0] | |
if(childElem){ | |
String childElemName = childElem.name() | |
log.debug "going throught childelements of list $childElemName" | |
def childElemVal = childElem.value()[0] | |
String aType = childElem.attribute("type") | |
if(!aType){ | |
if(childElemName.endsWith("_list")){ | |
def xmlListObj=[] | |
childElem.children().each{ it -> | |
Integer listObjId= null | |
String listObjIdStr = it.id.text() | |
if(listObjIdStr) listObjId = listObjIdStr.toInteger() | |
xmlListObj<<parseXmlClosure(it,curObj,user,listObjId) | |
} | |
xmlMap."$v" = xmlListObj | |
}else | |
xmlMap."$v" = childElemVal | |
} | |
else if(aType==SingUtils.INTEGER_TYPE) xmlMap."$v" = childElemVal.toInteger() | |
else if(aType==SingUtils.DATETIME_TYPE)xmlMap."$v" = new Date().parse("yyyy-M-d H:m:s",childElemVal.toString()) | |
} | |
} | |
def aObj=null | |
if(xmlMap) | |
aObj = domainClz.createOrUpdate(rootName,domainClz,xmlMap,curObj,parentObj,user) | |
else | |
log.debug "No xmlMap properties found,Make sure XML_ELEMENT_MAP of $domainClz has the correct Mappings " | |
return aObj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment