Questions tagged [xmlslurper]

XMLSlurper is a Groovy class that makes parsing and working with XML simpler than with Java.

You can read more here

241 questions
86
votes
2 answers

Groovy XmlSlurper vs XmlParser

I searched for a while on this topic and found some results too, which I am mentioning at the end of post. Can someone help me precisely answer these three questions for the cases listed below them? For which use-cases using XmlSluper makes more…
kdabir
  • 9,623
  • 3
  • 43
  • 45
33
votes
2 answers

How can I check for the existence of an element with Groovy's XmlSlurper?

I'm trying to determine whether an XML element exists with Groovy's XmlSlurper. Is there a way to do this? For example: How do I check whether the bar element exists?
Josh Brown
  • 52,385
  • 10
  • 54
  • 80
26
votes
2 answers

How to work around Groovy's XmlSlurper refusing to parse HTML due to DOCTYPE and DTD restrictions?

I'm trying to copy an element in an HTML coverage report, so the coverage totals appear at the top of the report as well as the bottom. The HTML starts thus and I believe is well-formed:
android.weasel
  • 3,343
  • 1
  • 30
  • 41
18
votes
3 answers

tag0 namespace added for elements in default namespace

I'm trying to parse and modify a Maven's pom.xml using Groovy's XmlSlurper. My pom.xml declares the namespace xsi.
stivlo
  • 83,644
  • 31
  • 142
  • 199
12
votes
2 answers

Namespace handling in Groovys XmlSlurper

The situation: def str = """ sudo make me a sandwich! """ def xml = new XmlSlurper().parseText(str) println xml.bar The output of this snippet is # sudo…
codeporn
  • 1,000
  • 1
  • 13
  • 32
12
votes
2 answers

Groovy XmlSlurper: Find elements in XML structure

Let's say there is the following XML structure: Field #1 1 Field…
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
12
votes
2 answers

XmlSlurper.parse(uri) with HTTP basic authentication

I need to grab a data from XML-RPC web-service. new XmlSlurper().parse("http://host/service") works fine, but now I have a particular service that requires basic HTTP authentication. How can I set username and password for parse() method, or modify…
mkuzmin
  • 775
  • 2
  • 7
  • 13
11
votes
2 answers

How can I use relative paths to external response files for soapUI MockService

What I've Done I am using soapUI (3.6.1 Free version) mock services to serve up specific data to 2 client applications I am testing. With some simple Groovy script I've set up some mock operations to fetch responses from specific files based on the…
Mark
  • 113
  • 1
  • 1
  • 7
10
votes
0 answers

cannot resolve symbol ConfigSlurper and XmlSlurper after upgrade to AS 3.0

I get cannot resolve symbol errors for ConfigSlurper and XmlSlurper in my build.gradle after upgrading Android Studio to 3.0, does it require code changes in the new AS? or any replacement for them? Attach error screenshots:
Beeing Jk
  • 3,796
  • 1
  • 18
  • 29
9
votes
3 answers

How to read the hyphenated attribute names (Eg. model_name) while parsing xml using XmlSlurper

I am trying to read an attribute while parsing XML using XmlSlurper in Groovy. When I try to read the hyphenated attribute model-number I am getting an exception.
9
votes
1 answer

MalformedURLException when using XmlSlurper

I have following code snippet in groovy: s = ''' My title This is body! ''' new XmlSlurper().parse(s) It gives following exception: java.net.MalformedURLException: no protocol:…
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
9
votes
1 answer

Groovy: Correct Syntax for XMLSlurper to find elements with a given attribute

Given a HTML file with the structure html -> body -> a bunch of divs what is the correct groovy statement to find all of the divs with a non blank tags attribute? The following is not working: def nodes = html.body.div.findAll { it.@tags != null…
Peter Kelley
  • 2,350
  • 8
  • 26
  • 46
8
votes
3 answers

Using XmlSlurper: How to select sub-elements while iterating over a GPathResult

I am writing an HTML parser, which uses TagSoup to pass a well-formed structure to XMLSlurper. Here's the generalised code: def htmlText = """

Heading 2

  1. Andrew Whitehouse
    • 2,738
    • 3
    • 31
    • 35

7
votes
2 answers

Parsing (very) large XML files with XmlSlurper

I am kind of new to Groovy and I am trying to read a (quite) large XML file (more than 1Gb) using XmlSlurper, which is supposed to work wonders with large files due to the fact that it doesn't build the whole DOM in memory. Nevertheless I keep…
Jérémie Clos
  • 11
  • 2
  • 10
6
votes
2 answers

How do you remove attributes from a node using Groovy's XMLSlurper and GPathResult?

I need to remove the attributes from a body node in some parsed HTML (converted to XML).
Peter Kelley
  • 2,350
  • 8
  • 26
  • 46
1
2 3
16 17