Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to turn an xmlElement into text #91

Open
jhonathas opened this issue Dec 4, 2022 · 1 comment
Open

Is it possible to turn an xmlElement into text #91

jhonathas opened this issue Dec 4, 2022 · 1 comment

Comments

@jhonathas
Copy link

For example:

<features>
  <feature>example 1</feature>
  <feature>example 1</feature>
</features>

xpath(doc, ~x"./features") |> to_string()

And I would like it to print the exact block in XML format instead of an xmlElement

<features>
  <feature>example 1</feature>
  <feature>example 1</feature>
</features>
@Adzz
Copy link

Adzz commented Dec 5, 2022

You can do it like this:

xml = """
<features>
  <feature>example 1</feature>
  <feature>example 1</feature>
</features>
"""
extract = SweetXml.xpath(xml, ~x"/features")
['<?xml version=\"1.0\"?>' | xml_snippet] = :xmerl.export([extract], :xmerl_xml)
Enum.join(xml_snippet, "") |> IO.puts

There is also a PR to add something similar to the library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants