read and update xml using groovy ,
read xml file in groovy to read xml file , using XmlSlurper().parseText and display its content ;xml file: <?xml version='1.0' encoding='UTF-8'?>
<Records>
<Line>
<Field1>ABC</Field1>
<Field2>123</Field2>
<Field3>XXX</Field3>
<Field4>567890</Field4>
</Line>
</Records>;
ChatGPT
You can use the XmlSlurper class in Groovy to parse an XML file and display its content. Here's a Groovy script that reads the XML content you provided and displays it:
groovy
Copy code
def xmlText = """<?xml version='1.0' encoding='UTF-8'?>
<Records>
<Line>
<Field1>ABC</Field1>
<Field2>123</Field2>
<Field3>XXX</Field3>
<Field4>567890</Field4>
</Line>
</Records>"""
def records = new XmlSlurper().parseText(xmlText)
// Display XML content
println "Root Element Name: ${records.name()}"
records.Line.each { line ->
println "Line Element:"
println " Field1: ${line.Field1.text()}"
println " Field2: ${line.Field2.text()}"
println " Field3: ${line.Field3.text()}"
println " Field4: ${line.Field4.text()}"
}
------------------------