Questions tagged [xmlslurper]
XMLSlurper is a Groovy class that makes parsing and working with XML simpler than with Java.
xmlslurper
244
questions
88
votes
2
answers
31k
views
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?
...
34
votes
2
answers
37k
views
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:
<foo>
<bar/>
</foo>
How do I check whether the bar ...
26
votes
2
answers
13k
views
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:
<?xml ...
18
votes
3
answers
7k
views
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.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http:...
12
votes
2
answers
13k
views
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 ...
12
votes
2
answers
28k
views
Groovy XmlSlurper: Find elements in XML structure
Let's say there is the following XML structure:
<Data>
<DataFieldText>
<DataFieldName>Field #1</DataFieldName>
<DataFieldValue>1</DataFieldValue&...
11
votes
2
answers
15k
views
Namespace handling in Groovys XmlSlurper
The situation:
def str = """
<foo xmlns:weird="http://localhost/">
<bar>sudo </bar>
<weird:bar>make me a sandwich!</weird:bar>
</foo>
"""
def xml = new ...
11
votes
2
answers
32k
views
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 ...
11
votes
0
answers
729
views
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?
...
10
votes
1
answer
6k
views
MalformedURLException when using XmlSlurper
I have following code snippet in groovy:
s = '''
<html>
<head>
<title>My title</title>
</head>
<body>
This is body!
</body>
</html>'''
new XmlSlurper()...
10
votes
3
answers
5k
views
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.
<router name="b" id="x" ...
9
votes
1
answer
14k
views
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 ...
8
votes
3
answers
12k
views
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 = """
<html>
<body>
<div id="divId" class="...
7
votes
2
answers
6k
views
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 ...
6
votes
1
answer
7k
views
XmlSlurper: How to change the text of a dynamic node
<Messdaten>
<EL_NR>NAYP99</EL_NR>
<EL_NR_Original/>
<Erfassungsdatum>2012-12-12 11:58:54.000</Erfassungsdatum>
<Massnahme>Lot_Hold</Massnahme>
...
6
votes
1
answer
5k
views
Groovy - XmlSlurper - read attributes into a Map
<racebet amount="8.89" id="6852465" bettype="K" instance="1" type="csf" />
What is the best way to create a map containing the attributes as keys and the corresponding values?
thanks.
6
votes
1
answer
10k
views
Groovy Node.depthFirst() returning a List of Nodes and Strings?
I'm hoping someone will just point out something obvious that I'm missing here. I feel like I've done this a hundred times and for some reason tonight, the behavior coming from this is throwing me for ...
6
votes
2
answers
5k
views
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).
6
votes
1
answer
2k
views
extracting parts of HTML with groovy
I need to extract a part of HTML from a given HTML page. So far, I use the XmlSlurper with tagsoup to parse the HTML page and then try to get the needed part by using the StreamingMarkupBuilder:
...
6
votes
1
answer
3k
views
Change XML tag name
I want to transform an XML document which I have parsed with XmlSlurper. The (identical) XML tag names should be replaced with the value of the id attribute; all other attributes should be dropped. ...
5
votes
1
answer
8k
views
Writing updated XML to originally parsed file
I have a gradle.build where I am trying to:
read an XML file
use XmlSlurper to update an attribute in the read XML file
write the updated XML back to the originally parsed xml file.
The third step ...
5
votes
3
answers
9k
views
How to remove an element in Groovy using XmlSlurper?
For example, how can I remove all tags with name one in rootNode programmatically?
def rootNode = new XmlSlurper().parseText(
'<root><one a1="uno!"/><two>Some text!</two>&...
5
votes
2
answers
2k
views
How to get the next sibling with GPathResult
How can I get the next sibling of an GPathResult? For example I have the following code:
def priorityIssue = xmlReport.'**'.find { Issue ->
Issue.Priority.text() == priority
}
How do I get ...
5
votes
1
answer
2k
views
groovy - problem parsing xml
I am new to Groovy and I am trying to parse both a valid rest resource and an invalid one.
For example:
this code works fine -
def entity = new XmlSlurper().parse('http://api.twitter.com/1/users/...
5
votes
2
answers
6k
views
Jenkins: Using XmlSlurper In Declarative Pipeline
Using XmlSlurper, I am trying to read an XML file (specifically Web.config from a .Net-based API) as part of a Jenkins pipeline. I do not seem to be able to access any attributes of elements. The ...
4
votes
1
answer
723
views
Fetching node from xml
I don't understand why this code fails to fetch a certain node from an xml string.
The code below will throw this error: groovy.util.slurpersupport.NodeChildren.attributes() is applicable for argument ...
4
votes
2
answers
4k
views
Extract URL from href-tag in groovy
I need to parse a malformed HTML-page and extract certain URLs from it as any kind of Collection.
I don't really care what kind of Collection, I just need to be able to iterate over it.
Let's say we ...
4
votes
2
answers
4k
views
Converting xml to domain object in Grails
I'm a grails newbie working on a project for fun. I'm serializing a class like this:
def msg = (listing as XML).toString()
the trying to deserialize a class using the XMLSlurper like this:
def ...
4
votes
2
answers
8k
views
Groovy pretty print XmlSlurper output from HTML?
I am using several different versions to do this but all seem to result in this error:
[Fatal Error] :1:171: The prefix "xmlns" cannot be bound to any namespace explicitly; neither can the namespace ...
4
votes
1
answer
20k
views
How to read XML file in groovy?
I am trying to read XML file in groovy with below lines of code
def xml=new XmlSlurper().parse("C:\2011XmlLog20110524_0623")
xml.Document.BillID.each{
println it}
I am getting file not found ...
4
votes
0
answers
327
views
Jenkins node attribute access returns boolean instead of value
I'm trying to parse XML in Jenkins pipeline using XmlSlurper.
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite>
<properties>
<property ...
3
votes
2
answers
13k
views
How to parse non-well formatted HTML with XmlSlurper
I'm trying to parse a non-well-formatted HTML page with XmlSlurper, the Eclipse download site The W3C validator shows several errors in the page.
I tried the fault-tolerant parser from this post
@...
3
votes
2
answers
6k
views
Groovy delete a tag in a XMLSlurper, replaceNode {} does nothing
I am parsing some XML with XMLSlurper (groovy 1.7.4) and I need to delete a tag (not make it empty!). Here is a code sample illustrating it:
import groovy.xml.StreamingMarkupBuilder
def CAR_RECORDS =...
3
votes
1
answer
2k
views
Change xml element/tag name using XmlSlurper or XmlParser
I have an xml that looks like this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Samples>
<Sample>
<Name>
Sample1
</Name>
<Date>...
3
votes
1
answer
1k
views
collect attributes and values into string list
I have xml data looking like this:
<persons>
<person key="M">John Doe</person>
<person key="N">Jane Doe</person>
</persons>
I want to collect them into a list ...
3
votes
1
answer
5k
views
Reading XML element with XmlSlurper in Groovy
I'd like to parse an XML document (SOAP request message) for a particular element. The document is stored in requestContent and looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<soap:...
3
votes
2
answers
1k
views
Is it possible to parse sub-trees with Groovy XMLSlurper
Does anyone know whether it is possible to utilise XMLSlurper in a fashion that means individual sub-trees can be pulled from a very large XML document and processed individually?
Imagine you've got ...
3
votes
1
answer
3k
views
Sorting XML in Groovy
I have looked at the documentation on sorting XML with Groovy
def records = new XmlParser().parseText(XmlExamples.CAR_RECORDS)
assert ['Royale', 'P50', 'HSV Maloo'] == records.car.sort{ it.'@year'....
3
votes
2
answers
787
views
XmlSlurper: Obtain the line number of groovy.util.slurpersupport.NodeChild in original file
I am using XmlSlurper to parse an XML file for processing.
I need to find the line number, of some matching criteria, within the file.
Here is what I have so far:
def void findServlets() {
...
3
votes
1
answer
3k
views
Nested GPath expressions with XmlSlurper and findAll
I'm trying to analyse an XML tree using XmlSlurper and GPath, and the behaviour of the findAll method confuses me.
Say, for example, that you have the following XML tree:
<html>
<body&...
3
votes
1
answer
1k
views
Parsing XML in Groovy with namespace and entities
Parsing XML in Groovy should be a piece of cake, but I always run into problems.
I would like to parse a string like this:
<html>
<p>
This is a <span>test</span> ...
3
votes
1
answer
622
views
can I use XmlSlurper directly on a w3c.dom.Node object
I am experimenting with GroovyWS in the hope of completely replacing Axis2 client code.
One of the Webservice operations I call returns fragments of XML, which I need to turn into Groovy Beans.
I am ...
3
votes
0
answers
271
views
How do I extract XML tags similar to XPATH with the XmlSlurper API in Java?
I am able to traverse the XML tree by importing the XmlSlurper API, but how do I extract specific tags from the XML like with XPATH? I want to extract them using the XmlSlurper API in Java in a way ...
3
votes
1
answer
1k
views
Groovy XMLSlurper appendNode - how force it to take effect?
I understand that XML document changes are not immediate when using Groovy's XMLSlurper and StreamingMarkupBuilder. However, I'm not happy having to do a lot of processing whenever I change a ...
2
votes
2
answers
5k
views
groovy XmlSlurper not parse my xml file
I have an xml, and I can't parse this file with xmlslurper.
Here a copy of my xml file :
<Entrezgene-Set>
<Entrezgene>
<Entrezgene_summary>The protein encoded by this gene is a ...
2
votes
1
answer
2k
views
Groovy XmlSlurper get value out of NodeChildren
I'm parsing HTML and trying to get full / not parsed value out of one particular node.
HTML example:
<html>
<body>
<div>Hello <br> World <br> !</div>
...
2
votes
2
answers
1k
views
XmlSlurper.appendNode doesn't change size
I work with XML using XmlSlurper. It works fine until I update it. The appendNode doesn't reflect the size.
How to worked with XmlSlurper after structure update?
XML definition:
def CAR_RECORDS = ''...
2
votes
3
answers
2k
views
How to use GPath with variable?
Let's say I have the following XML at hand
<Envelope>
<Body>
<analyzeEffectOfReplaceOfferResponse>
<productOfferings>
<productOffering>
<...
2
votes
1
answer
7k
views
Unable to add XMLSlurper to Eclipse Groovy project
I want to use XMLSlurper in my Groovy project in Eclipse.
I found out that i need to use Groovy-All Jar from https://search.maven.org/search?q=g:org.codehaus.groovy
to get those functionalities.
...
2
votes
1
answer
2k
views
Groovy: merging two XML files with GPathResult.appendNode(node) does not work
I need to write a script that takes several XML files and performs some operations basing on their contents. To make it easier to go through all the elements I wanted to merge all files into one XML ...