Forum Discussion

raghu1012's avatar
raghu1012
Occasional Contributor
5 years ago

Excel to XML generation using groovy script in SOAP UI

I am facing issue while reading excel file and generating XML strtcutre using groovy scripting. Please advise how can we handle where parentnode(Startmap) and child node(Startmap) has same name.


//tns1:BusinessModel/tns1:CONTACT/tns1:Address/tns1:Startmap
//tns1:BusinessModel/tns1:CONTACT/tns1:Startmap/tns1:BudgetPrice

Script:

def CONTACTNodeXPath = "//bpm:BusinessModel/bpm:CONTACT"
//Check and Create Startmap
checkAndCreateNode(holder, CONTACTNodeXPath, "Startmap")
UpdateStartmapNode(holder, dFormatter, sourceRow, fEval)

//Check and Create Address
checkAndCreateNode(holder, CONTACTNodeXPath, "Address")
UpdateAddressNode(holder, dFormatter, sourceRow, fEval)

void checkAndCreateNode(XmlHolder holder, String parentXPath, String nodeName)
{
def parentNode = holder.getDomNode(parentXPath)
log.info ("<R> value of parentnode:"+parentNode)
def parentNodeHolder = new XmlHolder(parentNode)
//log.info ("<R> value of parentNodeHolder:"+parentNodeHolder)
parentNodeHolder.namespaces["bpm"]="http://emra.corp.net/ecm/bpm"
def requestDoc = parentNode.getOwnerDocument()
log.info ("<R> value of requestDoc:"+requestDoc)
def childNode = parentNodeHolder.getDomNode("//bpm:" + nodeName)
log.info ("<R> value of childNode:"+childNode)
if(childNode == null)
{
childNode = requestDoc.createElementNS(parentNode.getNamespaceURI(), nodeName)
log.info ("<R> value of childNode inside if:"+childNode)
parentNode.appendChild(childNode)
}
}

void CheckAndUpdateNode(XmlHolder holder, String parentXPath, String nodeName, String nodeValue)
{
checkAndCreateNode(holder, parentXPath, nodeName)
holder[parentXPath + "/bpm:" + nodeName] = nodeValue
log.info ("<R> value of nodeValue :"+nodeValue)
}

 

void UpdateAddressNode(XmlHolder holder, DataFormatter dFormatter, XSSFRow sourceRow, XSSFFormulaEvaluator fEval)
{
//Updating the values of Nodes under BusinessModel/CONTACT/Address

def updateAddressNodeXPath = "//bpm:GenerateDocumentRequest/bpm:BusinessModel/bpm:CONTACT/bpm:Address"

CheckAndUpdateNode(holder, updateAddressNodeXPath, "Startmap", dFormatter.formatCellValue(sourceRow.getCell(1286), fEval))
}

void UpdateStartmapNode(XmlHolder holder, DataFormatter dFormatter, XSSFRow sourceRow, XSSFFormulaEvaluator fEval)
{
//Updating the values of Nodes under BusinessModel/CONTACT/Startmap

def updateStartmapNodeXPath = "//bpm:BusinessModel/bpm:CONTACT/bpm:Startmap"

CheckAndUpdateNode(holder, updateStartmapNodeXPath, "BudgetPrice", dFormatter.formatCellValue(sourceRow.getCell(1291), fEval))
}

Error:
An error occurred [Ambiguous method overloading for method com.eviware.soapui.support.XmlHolder#<init>.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface org.apache.xmlbeans.XmlObject]
[interface org.w3c.dom.Node]], see error log for details