lukeses
SweetXML / Xpath - parsing a parent of node
Hi,
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 (GitHub - kbrw/sweet_xml · GitHub)
A script shows, what I’m trying to achieve:
import SweetXml
xml =
"""
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Con>
<ID>123456782</ID>
<StatusData>
<StatusCode>A</StatusCode>
</StatusData>
<StatusData>
<StatusCode>A</StatusCode>
</StatusData>
</Con>
</Response>
"""
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.
First Post!
dimitarvp
I’m not seeing that in your example XML though? How could it be located if it doesn’t exist?
Popular in Questions
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
How to handle excepions in elixir?
Suppose i have A, B, C ,D, E modules. and each module has get() function.
A.get() method will call t...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Other popular topics
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








