2

Let's say I have the following XML document:

<Devices>
    <Scanners>
        <atom:link href="http://localhost/111" rel="http://1" />
        <atom:link href="http://localhost/222" rel="http://2" />
    </Scanners>
    <Printers>
        <atom:link href="http://localhost/333" rel="http://3" />
        <atom:link href="http://localhost/444" rel="http://4" />
    </Printers>
    <atom:link href="http://localhost/555" rel="http://5" />
</Devices>

Using REST assured's XmlPath I'd like to read all <atom:link> nodes - actually their list of attributes - into a list, regardless of where the node is located in the tree. So far my code looks like this:

XmlPath xmlPath = new XmlPath(response);
// This gives me a list of five entries --> OK
List<Node> linkNodes = xmlPath.get("depthFirst().findAll { it.name() == 'link' }");
// This prints five empty lines --> NOT OK
for (Node linkNode : linkNodes) {
  System.out.println(linkNode.get("@href"));
}

What am I missing here?

Robert Strauch
  • 12,055
  • 24
  • 120
  • 192

1 Answers1

4

Would it be sufficient to just do the following?

List<String> links = xmlPath.get("**.findAll { it.name() == 'link' }.@href");
...
Johan
  • 37,479
  • 32
  • 149
  • 237
  • this saved me so much time. Can you please let me know where can I find further options like this. I have looked up the xmlPath restassured doc but the attribute fetching was not mentioned there. – niharika_neo Jun 20 '17 at 06:14