kvcsks
3 years agoOccasional Visitor
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) {
log.info("Created an element with qualified name: " + qName)
def xml = SampleXmlUtil.createSampleForElement( el )
log.info("xml document: " + xml)
} else {
log.warn("Could not create a non-existing element with qualified name: " + qName);
}