Package dev.frostlake.values
Class XmlVariants
java.lang.Object
dev.frostlake.values.XmlVariants
Snowflake's XML-in-VARIANT model. An XML element is an ordinary variant OBJECT with the shape
{"$": content, "@": "tagname", "@attr": value, "childname": index} — the classification is
STRUCTURAL (live-verified: PARSE_JSON('{"$":1,"@":"b"}') reports TYPEOF XML and renders as
<b>1</b>), so no separate runtime type exists: any object carrying both a "$"
member and a textual "@" member is XML. Content is a scalar (single text), a single child
element object, or an array of text/element pieces; attributes are "@name" members; each
distinct child element name also appears as a member holding the content index of its first
occurrence.
This class renders that model back to XML text in Snowflake's compact form (the
TO_XML / ::VARCHAR rendering: no indentation, attributes sorted by name,
<a></a> for empty elements, &/</> escaped).
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcompactXml(tools.jackson.databind.JsonNode element) The compact XML text of an element node (the TO_XML rendering).static voidescapeAttribute(String text, StringBuilder out) Escapes attribute values:& < > ".static voidescapeText(String text, StringBuilder out) Escapes element text content:& < >.static booleanisXmlElement(tools.jackson.databind.JsonNode node) Whether the node is an XML element in Snowflake's structural sense.static booleanmightBeXmlText(String canonicalJson) Fast pre-check for canonical variant TEXT before parsing: every XML element's canonical JSON starts with{"$":because object keys sort and$precedes every other key.static StringprettyXml(tools.jackson.databind.JsonNode element) The DISPLAY text of an XML variant — Snowflake pretty-prints: an element whose content holds child ELEMENTS puts each child on its own line at +2 spaces and the closing tag back at the parent's indent (live:<r a="1">\n <b>2</b>\n</r>); text-only elements stay inline.
-
Method Details
-
isXmlElement
public static boolean isXmlElement(tools.jackson.databind.JsonNode node) Whether the node is an XML element in Snowflake's structural sense. -
mightBeXmlText
Fast pre-check for canonical variant TEXT before parsing: every XML element's canonical JSON starts with{"$":because object keys sort and$precedes every other key. -
compactXml
The compact XML text of an element node (the TO_XML rendering). -
prettyXml
The DISPLAY text of an XML variant — Snowflake pretty-prints: an element whose content holds child ELEMENTS puts each child on its own line at +2 spaces and the closing tag back at the parent's indent (live:<r a="1">\n <b>2</b>\n</r>); text-only elements stay inline. -
escapeText
Escapes element text content:& < >. -
escapeAttribute
Escapes attribute values:& < > ".
-