Reputation: 241
Hi In Groovy I need to remove part of string the string.
<Results xsi:type="xsd:string"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Updated User
id:nish.test11</Results>
should look like " Updated User id:nish.test11
how can i do that?
Upvotes: 0
Views: 322
Reputation: 20699
If I run the code:
""" <Results xsi:type="xsd:string"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Updated User
id:nish.test11</Results>""".replaceAll( /<\/?[^<>]>/, '' ).replaceAll( /[\n\s]+/, ' ' )
it gives me
Updated User id:nish.test11
as output
Upvotes: 0
Reputation: 9868
As the content looks like an XML,
def xml = """
<Results xsi:type="xsd:string"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Updated User
id:nish.test11</Results>
"""
it's better to use XmlSlurper than parsing/extracting strings by hand
def result = new XmlSlurper().parseText(xml)
println result.toString()
this gives the desired result (the content of the Result
)
Upvotes: 1