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_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 soap_header == nil, do: xml @doc "Removes wrapper taken from config/message/wrappers" def remove_message_wrapper(xml, message) when message == nil, do: xml def remove_message_wrapper(xml, [ wrapper: { wrapper, attributes}, req: req, wrapper_response: {res_wrapper, res_attributes}, res: res ]) do xml = Regex.replace(~r/(<#{to_string(res_wrapper)}[\S\s]*><#{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 {: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