Class XmlVariants

java.lang.Object
dev.frostlake.values.XmlVariants

public final class XmlVariants extends Object
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, &amp;/&lt;/&gt; escaped).

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    compactXml(tools.jackson.databind.JsonNode element)
    The compact XML text of an element node (the TO_XML rendering).
    static void
    Escapes attribute values: & < > ".
    static void
    Escapes element text content: & < >.
    static boolean
    isXmlElement(tools.jackson.databind.JsonNode node)
    Whether the node is an XML element in Snowflake's structural sense.
    static boolean
    mightBeXmlText(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 String
    prettyXml(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static boolean mightBeXmlText(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.
    • compactXml

      public static String compactXml(tools.jackson.databind.JsonNode element)
      The compact XML text of an element node (the TO_XML rendering).
    • prettyXml

      public static String prettyXml(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.
    • escapeText

      public static void escapeText(String text, StringBuilder out)
      Escapes element text content: & < >.
    • escapeAttribute

      public static void escapeAttribute(String text, StringBuilder out)
      Escapes attribute values: & < > ".