ToCompactXML[expr]
generates an equivalent SymbolicXML expression that suppresses all the redundant namespace information for elements and attributes in expr.
ToCompactXML[expr,patt]
suppresses only namespaces that match patt.
ToCompactXML
ToCompactXML[expr]
generates an equivalent SymbolicXML expression that suppresses all the redundant namespace information for elements and attributes in expr.
ToCompactXML[expr,patt]
suppresses only namespaces that match patt.
Details and Options
- To use ToCompactXML, you first need to load the XML Package using Needs["XML`"].
- The following option can be given:
-
"AttributesDefaultNameSpace" "NullNameSpace" controls how attribute namespaces are abbreviated
Examples
Basic Examples (1)
Needs["XML`"]XML with explicit namespace information:
xmlNull = XMLElement[{"A", "foo"}, {"xmlns" -> "A", {"", "att"} -> "val"}, {}];
xmlSame = XMLElement[{"A", "foo"}, {"xmlns" -> "A", {"A", "att"} -> "val"}, {}];
xmlDifferent = XMLElement[{"A", "foo"}, {"xmlns" -> "A", {"B", "att"} -> "val"}, {}];ToCompactXML suppresses redundant namespace information for elements. Attributes in the null namespace always get compacted, regardless of the setting of "AttributesDefaultNameSpace":
ToCompactXML[xmlNull, "AttributesDefaultNameSpace" -> "NullNameSpace"]ToCompactXML[xmlNull, "AttributesDefaultNameSpace" -> "ElementNameSpace"]Attributes in the same default namespace as the element only get compacted when "AttributesDefaultNameSpace" is "ElementNameSpace":
ToCompactXML[xmlSame, "AttributesDefaultNameSpace" -> "NullNameSpace"]ToCompactXML[xmlSame, "AttributesDefaultNameSpace" -> "ElementNameSpace"]Attributes in other namespaces do not get compacted:
ToCompactXML[xmlDifferent, "AttributesDefaultNameSpace" -> "NullNameSpace"]ToCompactXML[xmlDifferent, "AttributesDefaultNameSpace" -> "ElementNameSpace"]If the namespace of a tag is explicit but different from the default, attributes will not be compacted:
ToCompactXML[XMLElement[{"A", "foo"}, {"xmlns" -> "B", {"A", "att"} -> "val"}, {}], "AttributesDefaultNameSpace" -> "ElementNameSpace"]The default namespace may be inherited from containing tags:
ToCompactXML[XMLElement["root", {"xmlns" -> "B"}, {XMLElement[{"A", "foo"}, {{"B", "att"} -> "val"}, {}]}], "AttributesDefaultNameSpace" -> "ElementNameSpace"]