Forum Discussion

kvcsks's avatar
Occasional Visitor
3 years ago

Create XML from XSD file

I try to create XML file with use of an XSD in Groovy script. I have found this solution, but not sure, how to set node values.

import org.apache.xmlbeans.*
import javax.xml.namespace.*

// provide file path to XSD file
def xsdObject = XmlObject.Factory.parse(new File(xsdFilename))
def xmlBeans = new XmlBeans()
def loader = xmlBeans.loadXsd( xsdObject )

namespace = 'urn:yahoo:api' // replace
elementName = 'Error'  // replace
def qName = new QName(namespace, elementName)
def el = loader.findElement(qName)

if (el != null) {"Created an element with qualified name: " + qName)
def xml = SampleXmlUtil.createSampleForElement( el )"xml document: " + xml)
} else {
log.warn("Could not create a non-existing element with qualified name: " + qName);


No RepliesBe the first to reply