defmodule NDCNormalize do def remove_soap_tags(xml, soap_namespace) when soap_namespace != nil, do: Regex.replace(~r/(<\/?#{soap_namespace}:.*?>)/s, xml, "") def remove_soap_tags(xml, soap_namespace) when soap_namespace == nil, do: xml def remove_declaration(xml), do: Regex.replace(~r/<\?xml[\S\s]*\?>/, xml, "") def remove_soap_header(xml, {header, attrs, list}), do: Regex.replace(~r/(<#{to_string(header)}[\S\s]*?>[\S\s]*?<\/#{to_string(header)}>)/s, xml, "") def remove_soap_header(xml, soap_header) when is_binary(soap_header), do: xml #Regex.replace(~r/(<#{soap_header}[\S\s]*?>[\S\s]*?<\/#{soap_header}>)/s, xml, "") def remove_soap_header(xml, soap_header) when soap_header == nil, do: xml #def remove_namespace(xml, namespace) when namespace != nil, do: Regex.replace(~r/(<#{namespace}:)/s, Regex.replace(~r/(<#{to_string(res)}>)/s, xml, "") Regex.replace(~r/(<\/#{to_string(res)}><\/#{to_string(res_wrapper)}[\S\s]*>)/s, xml, "") end def check_ndc_errors(xml) do #if Regex.match?(~r/[\s]*[\S\s]*<\/Error>[\s]*<\/Errors>/, xml) do if Regex.match?(~r/[\s]*(([\S\s]*<\/Error>)|())[\s]*<\/Errors>/, xml) do {:error, xml} else if Regex.match?(~r/<(soap:)?Fault>[\s]*[\S\s]*<\/faultcode>[\s]*<\/(soap:)?Fault>/, xml) do {:error, xml} else {:ok, xml} end end end end