SweetXML / Xpath - parsing a parent of node


I have a problem with parsing an XML. I’m trying to get a parent of the node for number of nodes.

I use for that purpose SweetXml library (https://github.com/kbrw/sweet_xml)

A script shows, what I’m trying to achieve:

import SweetXml

xml =
<?xml version="1.0" encoding="utf-8"?>

xpath(xml, ~x"//Response/Con/StatusData"l,
  status_code: ~x"./StatusCode/text()"s,
  id: ~x"./../ID/text()"s
) |> IO.inspect(label: "RESULT")

# Terminal response:
# RESULT: [%{id: "", status_code: "A"}, %{id: "", status_code: "A"}]

# Expected Terminal response:
# RESULT: [%{id: "123456782", status_code: "A"}, %{id: "123456782", status_code: "A"}]```

Below, I’m presenting sth similar, which works:

xpath(xml, ~x"//StatusData/ancestor::Con/ID/text()"sl) |> IO.inspect(label: "RESULT_2")

# Terminal response:
# RESULT_2: ["123456782", "123456782"]

Do you have any idea, what should be instead of the line: id: ~x"./../ID/text()"s?

BTW, I know I may do this step by step: getting ID, then playing with Enum.map, but it looks like my case should be supported by SweetXML/Xpath.

I’m not seeing that in your example XML though? How could it be located if it doesn’t exist?


I have edited a question (made a small mistake, when anonymizing a question), I meant a line: id: ~x"./../ID/text()"s