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
6
votes
1 answer

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: import groovy.xml.StreamingMarkupBuilder def html =…
rdmueller
  • 10,742
  • 10
  • 69
  • 126
6
votes
1 answer

Groovy - XmlSlurper - read attributes into a Map

What is the best way to create a map containing the attributes as keys and the corresponding values? thanks.
saravana_pc
  • 2,607
  • 11
  • 42
  • 66
6
votes
1 answer

XmlSlurper: How to change the text of a dynamic node

NAYP99 2012-12-12 11:58:54.000 Lot_Hold 50 OK 72 That is…
Endogen
  • 589
  • 2
  • 12
  • 24
6
votes
1 answer

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. Starting from this code: def xml = """
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
6
votes
1 answer

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 a loop. I'm reading in some XML from a public…
James
  • 1,391
  • 2
  • 14
  • 20
5
votes
1 answer

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/show/slashdot.xml') println entity.name() println…
frank.C
  • 105
  • 1
  • 6
5
votes
2 answers

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 error I get is: No such field found: field…
voodoobilly
  • 405
  • 7
  • 18
5
votes
3 answers

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( 'Some text!' ) I tried rootNode.children().removeAll{ it.name() == 'one'…
Elderry
  • 1,902
  • 5
  • 31
  • 45
5
votes
2 answers

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 priorityIssue's next sibling? Thanks!
jonatzin
  • 922
  • 1
  • 13
  • 30
5
votes
1 answer

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 only works if I write the modified XML to a new…
Going Bananas
  • 2,265
  • 3
  • 43
  • 83
4
votes
1 answer

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 error though i have the file in my C drive..is there…
laxmi
  • 865
  • 6
  • 17
  • 27
4
votes
2 answers

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 for "xmlns" be bound to any prefix explicitly. I…
Миша Кошелев
  • 1,483
  • 1
  • 24
  • 41
4
votes
1 answer

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 types: () values: [] Thanks for any explanations…
user955732
  • 1,330
  • 3
  • 21
  • 48
4
votes
2 answers

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 have a structure like this: …
Jakunar
  • 156
  • 1
  • 2
  • 7
4
votes
2 answers

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 root = new XmlSlurper().parseText(listingString) def…
dalcantara
  • 1,613
  • 2
  • 21
  • 35
1
2
3
16 17