From 2cae9f246c959920938118bc814f51147494eb51 Mon Sep 17 00:00:00 2001 From: Anatoliy Kovalchuk Date: Mon, 13 Feb 2017 20:18:07 +0700 Subject: [PATCH] add doc_to_xml method for converting doc to xml string --- lib/sweet_xml.ex | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/sweet_xml.ex b/lib/sweet_xml.ex index 34d31c0..7f0b009 100644 --- a/lib/sweet_xml.ex +++ b/lib/sweet_xml.ex @@ -445,7 +445,6 @@ defmodule SweetXml do get_current_entities(parent, spec) |> spec.transform_fun.() end - def xpath(parent, sweet_xpath, subspec) do if sweet_xpath.is_list do current_entities = xpath(parent, sweet_xpath) @@ -554,6 +553,26 @@ defmodule SweetXml do %{sweet_xpath | transform_fun: fun} end + @doc ~S""" + Convert `doc` to XML string + + ## Examples + + iex> import SweetXml + iex> "

Some linked title

" + ...> |> parse() + ...> |> doc_to_xml() + "

Some linked title

" + iex> "
" + ...> |> parse() + ...> |> xpath(~x"/body/header/ul"e) + ...> |> doc_to_xml() + "" + """ + def doc_to_xml(doc) do + :xmerl.export([doc], :xmerl_xml) |> List.flatten() |> List.to_string() + end + defp _value(entity) do cond do is_record? entity, :xmlText ->