PhoenixmlDb.XQuery

XQueryResultSerializer

Serializes XQuery result items (nodes, atomic values, arrays, sequences) to strings.

#XQueryResultSerializer

Namespace: PhoenixmlDb.XQuery

Serializes XQuery result items (nodes, atomic values, arrays, sequences) to strings.

This serializer handles all XDM result types produced by the XQuery engine: document and element nodes are serialized as XML, atomic values use their string representation, and sequences/arrays are serialized by concatenating their items. For the simplest usage, call the static method. For repeated serialization with the same store, create an instance and call .

#Constructors

##ctor(PhoenixmlDb.XQuery.XdmDocumentStore,PhoenixmlDb.XQuery.OutputMethod)

Creates a new serializer backed by the given document store.

Parameters:

  • store — The document store used to resolve child nodes and namespaces during serialization.

  • method — The output method. Defaults to .

##ctor(PhoenixmlDb.XQuery.XdmDocumentStore,PhoenixmlDb.XQuery.SerializationOptions)

Creates a new serializer backed by the given document store with full serialization options.

Parameters:

  • store — The document store used to resolve child nodes and namespaces during serialization.

  • options — The serialization options.

#Methods

#AdaptiveTypedForm(Object)

Maps a non-basic atomic value to its adaptive constructor type local-name and canonical lexical string. The engine collapses some XSD subtypes onto a single CLR representation, so the local-name follows the runtime type: xs:dateTimeStamp is an (→ dateTime) and the duration subtypes collapse onto duration — matching the QT3 method-adaptive corpus expectations.

#AddCdataQName(Object,Collections.Generic.ISet<String>)

Adds a QName value to the CDATA section elements set, handling QName objects and string representations.

#CanEncode(Text.Encoding,String)

Checks whether the target encoding can represent the given string without data loss.

#CoerceToBool(Object,String,Boolean)

Coerces a serialization parameter value to boolean, handling xs:boolean, xs:untypedAtomic, and string values from XML-based parameters.

#CoerceToString(Object,String,Boolean)

Coerces a serialization parameter value to string, handling xs:untypedAtomic.

#EscapeAdaptiveString(String)

Escapes a string for the adaptive output method by doubling every double-quote (" → ""), per W3C Serialization 4.0 §6. This is distinct from JSON escaping (), which uses backslash escapes.

#FirstElementLocalName(PhoenixmlDb.Xdm.Nodes.XdmNode)

Returns the local name of the document element (for a document node) or of the element itself (for an element node), used to decide whether the implicit HTML5 DOCTYPE applies — it is emitted only when the outermost element is html.

#FormatAdaptiveDouble(Double)

Formats an xs:double in the canonical XPath exponential form required by the adaptive method (W3C Serialization 4.0 §6): a mantissa with a decimal point and a lowercase e exponent, e.g. 1.0e0, 1.5e2, -3.4e-5. INF/-INF/NaN keep their special lexical forms. This is adaptive-scoped and deliberately does NOT touch the global double formatter (), which emits the fixed-point canonical form expected elsewhere (e.g. 1).

#FormatJsonNumber(Object)

Formats a numeric XDM value for JSON output per XSLT/XQuery Serialization §11.1: integers print without a decimal point, decimals print in fixed notation with trailing zeros stripped, and xs:double / xs:float follow the XPath cast-to-string algorithm (fixed for |v| in [1e-6, 1e21), scientific otherwise). Without this, Convert.ToString routed through .NET defaults, producing "1E-05" where the JSON spec (QT3 Serialization-json-16) requires "0.00001".

#IsAdaptiveAtomic(Object)

Returns true if is an atomic value that the adaptive method serializes via . This covers the "basic" numeric types that need the adaptive-specific canonical double form (xs:double) plus every "non-basic" type that renders in constructor notation. xs:string and xs:boolean are intentionally excluded — they keep their dedicated bare/quoted handling in and .

#IsEncodable(Char,Text.Encoding)

Returns true if round-trips through (i.e. the encoding can represent it without a replacement character).

#IsHtml5

True when the requested HTML version is 5.x (default for the HTML method is 5.0).

#IsXhtmlVoid(String,String)

True when the element is a void (empty-content-model) element under the XHTML method, given the requested html-version and the element's namespace.

#ParseSerializationOptions(Collections.Generic.IDictionary<Object,Object>,Boolean)

Parses serialization options from a parameter map (as produced by XQuery map expressions or by ). Handles type coercion (xs:untypedAtomic to target types), validation, and error reporting per the XSLT/XQuery Serialization specification.

Parameters:

  • paramsMap — The parameter map. May be null for defaults.

  • paramsFromMap — True if the parameters came from a user-supplied XQuery map (stricter type checking).

Returns: Fully validated .

#ParseSerializationParamsElement(PhoenixmlDb.Xdm.Nodes.XdmElement,PhoenixmlDb.XQuery.INodeProvider)

Parses serialization parameters from an XML element (<output:serialization-parameters>) into a raw parameter map. Validates element structure per the XSLT/XQuery Serialization spec and raises SEPM0017/SEPM0018/SEPM0019 errors as appropriate.

#Serialize(Object,PhoenixmlDb.XQuery.XdmDocumentStore,PhoenixmlDb.XQuery.OutputMethod)

Static convenience method: serializes a single result item using the given store.

Parameters:

  • item — The XQuery result item.

  • store — The document store for node/namespace resolution.

  • method — The output method. Defaults to .

Returns: The serialized string representation.

#Serialize(Object,PhoenixmlDb.XQuery.XdmDocumentStore,PhoenixmlDb.XQuery.SerializationOptions)

Static convenience method: serializes a single result item using the given store and options.

Parameters:

  • item — The XQuery result item.

  • store — The document store for node/namespace resolution.

  • options — The serialization options.

Returns: The serialized string representation.

#Serialize(Object)

Serializes a single result item to a string.

Parameters:

  • item — The XQuery result item (node, atomic value, array, sequence, or null).

Returns: The serialized string representation.

#SerializeAdaptiveMember(Object,IO.TextWriter)

Serializes a single array member in adaptive method. A member may be a multi-item sequence (represented as object?[]): such a member renders parenthesized, with each item serialized per adaptive structured rules. A length-1 sequence unwraps to its single item; any other value is serialized directly.

#SerializeAdaptiveStructured(Object,IO.TextWriter)

Serializes an item that appears INSIDE a map or array in adaptive method. Strings are quoted with JSON escaping; booleans render as the function-call form true()/false() (W3C Serialization 4.0 §6, structured-item context — distinct from the bare top-level form); nested maps/arrays recurse; everything else delegates to . Distinct from top-level , which writes strings bare because at top level the convention is "give the user the string content directly".

#SerializeArrayAdaptive(Collections.Generic.List<Object>,IO.TextWriter)

Serializes an array in adaptive output format: [m1,m2,…]. Each member is serialized per adaptive rules via ; a member that is itself a multi-item (or empty) sequence renders parenthesized ((1,2,3), ()). Previously top-level arrays in adaptive mode fell through to the JSON array path, which used the wrong format and hard-errored on sequence members and on INF/NaN numerics.

#SerializeAsHtml(PhoenixmlDb.Xdm.Nodes.XdmNode,IO.TextWriter)

Serializes a node as HTML output, emitting DOCTYPE, meta charset, void elements, etc.

#SerializeAsXhtml(PhoenixmlDb.Xdm.Nodes.XdmNode,IO.TextWriter)

Serializes a node using the XHTML output method.

#SerializeMapAdaptive(Collections.Generic.IDictionary<Object,Object>,IO.TextWriter)

Serializes a map in adaptive output format: map{"key":"value",...}. Per W3C Serialization 4.0 §6 (Adaptive method), atomic values inside a structured item (map, array) follow these rules: xs:string → quoted, xs:boolean → bare true/false, numerics → bare lexical form. Earlier behavior emitted bare strings (map{key:value}), which collided with Saxon's adaptive output and tripped any caller that round-tripped the result through a JSON parser.

#SerializeNodeForJson(PhoenixmlDb.Xdm.Nodes.XdmNode)

Serializes a node to its XML string representation for use in JSON output.

#SerializeSuppressedChildren(PhoenixmlDb.Xdm.Nodes.XdmElement,Boolean,String)

Serializes the children of a suppress-indentation element to a string with indentation disabled, for injection into the parent writer via . Reuses with set so descendant elements are not re-suppressed. The element's own start/end tags are written by the caller through the parent (indenting) writer.

#ShouldSuppressIndentation(PhoenixmlDb.Xdm.Nodes.XdmElement,String)

Determines whether must have its content serialized without added indentation: either its expanded name appears in the set, or it carries an xml:space="preserve" attribute. The name is matched in both the qualified Q{uri}local form and, for a no-namespace element, the bare local name.

#WriteAdaptiveQuotedString(String,IO.TextWriter)

Serializes a typed atomic value in the adaptive method (W3C Serialization 4.0 §6). "Basic" types (xs:integer, xs:decimal, xs:double) render bare; xs:double uses the canonical XPath exponential form (1.0e0, 1.5e2, INF, -INF, NaN). Every other (non-basic) type renders in constructor notation xs:TYPE("canonicalLexical"), where the canonical lexical comes from the engine's existing string-value producer () and is NOT JSON-escaped (it is a lexical form, e.g. an ISO date). Writes a string-family value (xs:string and its subtypes, xs:anyURI, xs:untypedAtomic) as an adaptive-method quoted string: a leading ", the content with every " doubled to "" (W3C Serialization 4.0 §6 — NOT JSON backslash-escaping), and a trailing ".

#WriteAttributeValueEscaped(Xml.XmlWriter,String)

Writes an attribute value, escaping the characters that the XML output method must emit as numeric character references (see ). In an attribute, TAB/LF/CR are additionally escaped because an XML parser normalizes attribute whitespace, so a literal would not round-trip.

#WriteCDataEncodingAware(Xml.XmlWriter,String)

Writes text/attribute content, emitting numeric character references for characters that XmlWriter would otherwise pass through literally but the serialization spec requires escaped: CR (#xD), NEL (#x85), LINE SEPARATOR (#x2028), and DEL plus the C1 control range (#x7F–#x9F). In attribute content, TAB (#x9) and LF (#xA) are also escaped (attribute-value normalization). XmlWriter still handles &, <, >, and (for attributes) the quote, for the unescaped runs written via WriteString. Escapes a free-standing string as XML character data for the XML-family output methods: the markup characters & < > become entities, and CR (#xD), NEL (#x85), LINE SEPARATOR (#x2028), DEL and the C1 control range (#x7F–#x9F) become numeric character references so they survive a reparse. Mirrors the per-character rules of for the node path, but operates on a bare string. Writes a text node as a CDATA section for a cdata-section-element. A character that the target encoding cannot represent (e.g. a non-ASCII char under us-ascii) cannot appear in a CDATA section — which is literal — so it is emitted as a numeric character reference, splitting the section around it. Any ]]> in a CDATA run is split so the marked section stays well-formed. (QT3 Serialization-xml K2-Serialization-35.)

#WriteFunctionItem(PhoenixmlDb.XQuery.Ast.XQueryFunction,IO.TextWriter)

Writes a function item in adaptive method (W3C Serialization 4.0 §6). A named function reference renders as prefix:local#arity using the conventional prefix for a standard namespace, Q{uri}local#arity for an unknown namespace, or local#arity when the function has no namespace. An inline/anonymous function renders as (anonymous-function)#arity.

#WriteHtmlDoctype(IO.TextWriter,String)

Emits the leading DOCTYPE for the HTML method, if any. A DOCTYPE with a public and/or system identifier is always emitted; otherwise an HTML5 <!DOCTYPE html> is emitted only when the requested version is 5.x (HTML 4.0 output carries no implicit DOCTYPE).

#WriteManualXmlDeclaration(IO.TextWriter,Text.Encoding)

Writes an XML declaration directly to the output for the forced-declaration-on-element case (XmlWriter refuses a declaration in Fragment conformance). Honors the requested version (default 1.0), encoding, and standalone serialization parameters (QT3 method-xml K2-Serialization-18/22/23).

#WriteXhtmlDoctype(IO.TextWriter)

Emits the leading DOCTYPE for the XHTML method. HTML 5.0 always emits <!DOCTYPE html> (a bare doctype-public is ignored). HTML 4.0 emits a DOCTYPE only when a doctype-system is present (a bare doctype-public is dropped). When both public and system identifiers are present a PUBLIC declaration is emitted.

#Fields

Name Description
_inSuppressedSubtree True while serializing the subtree of a suppress-indentation element via a nested non-indenting writer, so nested suppressed elements are not re-processed.
FunctionNsPrefixes Maps the standard function-namespace URIs to their conventional prefixes for adaptive function-item serialization (W3C Serialization 4.0 §6).