I am trying to decode an XML document that has lines that are base64 encoded.
For this I first tried to read the XML document with XML Slurper and then convert it line by line and write all lines into a string. Unfortunately I didn't manage to iterate over the single elements.
Because the base64 lines always have a "==" at the end, I tried after I had all lines one after the other in a big string, to read the elements in a List. however, I get then again only a big string out and can not edit the elements again individually.
The document looks like this:
<root>
<item>
<LINE>base64encoded==</LINE>
</item>
<item>
<LINE>base64encoded==</LINE>
</item>
<item>
<LINE>base64encoded==</LINE>
</item>
<item>
<LINE>base64encoded==</LINE>
</item>
<item>
<LINE>base64encoded==</LINE>
</item>
</root>
thats my code
def root = new XmlSlurper().parseText(text)
def authorResult = root.item.LINE as String
List<String> items = Arrays.asList(authorResult.split("\\s=="));
and
root.each { thing ->
println "LINE index: ${LINE.@indexNum}"
}
}
But with noi luck, im stuck. Why both of my approaches didnt work? Pleas explain me what im doing wrong
This is my solution
String s =""
def root = new XmlSlurper().parseText(text)
def titles = root.'**'.findAll { node -> node.name() == 'LINE' }*.text()
for(def i = 0; i<titles.size();i++) {
Helpdecode = titles.get(i).toString()
def Help2 = Base64.getDecoder().decode(Helpdecode);
String s2 = new String(Help2)
s = s+s2
}
This code works perfectly on my machine. The code was transfered to a cloud and now im getting this error
org.codehaus.groovy.runtime.typehandling.GroovyCastException
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.