pub fn clear_xml_string(input: &str, remove_encoding_tag: bool) -> StringExpand description
Clean an XML string by removing namespace artifacts, collapsing inter-tag
whitespace, and optionally stripping the <?xml … ?> declaration.
This is a direct port of the PHP Strings::clearXmlString() from
sped-common. It performs the following transformations:
- Removes the
xmlns:default="http://www.w3.org/2000/09/xmldsig#"attribute. - Removes the
standalone="no"attribute. - Removes
default:namespace prefixes and:defaultsuffixes. - Strips
\n,\r, and\tcharacters. - Collapses whitespace between adjacent XML tags (
> <becomes><). - If
remove_encoding_tagistrue, removes the<?xml … ?>declaration.
§Examples
use fiscal_core::xml_utils::clear_xml_string;
let xml = "<root>\n <child>text</child>\n</root>";
assert_eq!(clear_xml_string(xml, false), "<root><child>text</child></root>");
let xml2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><a>1</a></root>";
assert_eq!(clear_xml_string(xml2, true), "<root><a>1</a></root>");