Questions tagged [gpath]

Path expression language integrated into Groovy which allows parts of nested structured data to be identified. Can be used to query XML and nested Plain Old Java Objects

An overview of GPath with some sample code can be found on the codehause.org site

http://groovy.codehaus.org/GPath

79 questions
22
votes
4 answers

How to find element by attribute value in GPath?

What is an alternative to this XPath //div[@id='foo'] in GPath? In general, where I can find this documentation?
yegor256
  • 102,010
  • 123
  • 446
  • 597
8
votes
4 answers

GPathResult to String without XML declaration

I'm converting GPathResult to String using def gPathResult = new XmlSlurper().parseText('') XmlUtil.serialize(gPathResult) It works fine, but I'm getting XML declaration in front of my XML How…
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
7
votes
1 answer

Groovy JSON/GPath query

Given the following JSON, I would like to extract the postal_code (either long_name or short_name). I've used JsonSlurper to ingest it into a variable and have tried various queries using find/contains/etc. to grab the node that has "postal_code"…
WXB13
  • 1,046
  • 3
  • 11
  • 17
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
6
votes
2 answers

GPathResult ..presence or absence of a node

My GPathResult can have a name node in one of the 3 ways 1) name node is present and has a value ex: John 2) name node exists, but has no value in it. 3) No name node exists at all. In Groovy code, how do i differenciate between the above 3 cases…
user1717230
  • 443
  • 1
  • 15
  • 30
5
votes
1 answer

Way to deep traverse a Groovy object with dot in string using GPath

The situation I have is that I'm querying MongoDB with a string for a field that is more than one level deep in the object hierarchy. This query must be a string. So for example I'm querying for something like this in Groovy: def queryField =…
Scott
  • 16,711
  • 14
  • 75
  • 120
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
4
votes
1 answer

I need a GPath query to select a node using a numeric index

How do I select from a parsed html document a specific element given its index. For example: ...
div1
div2
I want to select the second div but it seems to me GPath doesn't offer a solution like Xpath does.
SomeEUGuy
  • 187
  • 1
  • 1
  • 7
3
votes
1 answer

GPath expression for finding all attribute values by name

Looking for GPath expression to get list of attribute values using the attribute name: def xmltxt = """ sunny golf
raffian
  • 31,267
  • 26
  • 103
  • 174
3
votes
1 answer

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:
  • Element…
Nicolas Rinaudo
  • 6,068
  • 28
  • 41
2
votes
1 answer

Groovy : Class.forName().newInstance() error

I have this following method in which I return a List object using the List filteredList. I perform filteredList.each closure where I generate class at runtime and assign it a static type of ImField. static List
Abhishek Dasgupta
  • 578
  • 1
  • 8
  • 20
2
votes
0 answers

Find a node by name in RestAssured JPath

I got the following JSON { "response":{ "id":"XYZ", "header":[ { "nat":"1" } ], "summary":[ { "recordCreationDate":"29-Aug-2018", …
user3727540
  • 922
  • 3
  • 11
  • 30
2
votes
3 answers

How to use GPath with variable?

Let's say I have the following XML at hand some value
Yossi Even
  • 45
  • 8
2
votes
2 answers

Find XML Element by attribute value using dynamic GPath Expression

Following is a sample XML: X Y Z I want to get the element count which has…
Tapas Bose
  • 28,796
  • 74
  • 215
  • 331
2
votes
1 answer

Rest assured, using Gpath query gives an error "The parameter "..." was used but not defined. Define parameters using the JsonPath.params(...)"

I'm new to rest-assured and I'm currently spiking it in order to implement it in our testing framework. The problem I'm facing is to extract an object from a Json array from the REST response. The example json I'm using: { "MRData": { …
Spook_0088
  • 23
  • 2
  • 6
1
2 3 4 5 6