PhoenixmlDb.Core
XmlDocumentParser
Parses XML content (strings, streams, or readers) into an XDM node tree.
#XmlDocumentParser
Namespace: PhoenixmlDb.Xdm.Parsing
Parses XML content (strings, streams, or readers) into an XDM node tree.
This is the primary mechanism for converting XML text into the in-memory XDM representation used throughout PhoenixmlDb. The parser produces a ParseResult containing the XdmDocument root node and a flat list of all nodes in document order.
Node ID assignment: Each node receives a unique NodeId starting from startNodeId and incrementing monotonically. The document node receives the first ID, followed by elements, attributes, text nodes, etc., in document order. This sequential assignment enables efficient storage and retrieval.
Namespace interning: Namespace URIs are converted to NamespaceId values via the provided namespaceResolver function. This deduplicates namespace strings across the entire database, making namespace comparisons an integer operation.
Usage: This parser is used internally by PutDocumentAsync when storing documents, but is also available for direct use when you need to parse XML without storing it.
#Example
Parsing an XML string into an XDM tree:
var parser = new XmlDocumentParser(
documentId: new DocumentId(1),
startNodeId: new NodeId(1),
namespaceResolver: uri => namespaceTable.Intern(uri));
var result = parser.Parse("<root><item>Hello</item></root>");
var doc = result.Document;
Console.WriteLine($"Parsed {result.NodeCount} nodes");
#Constructors
##ctor(PhoenixmlDb.Core.DocumentId,PhoenixmlDb.Core.NodeId,Func<String,PhoenixmlDb.Core.NamespaceId>,Boolean)
Creates a new XML parser that will assign the specified document and node IDs.
Parameters:
-
documentId— TheDocumentIdto assign to all parsed nodes. -
startNodeId— The firstNodeIdto assign. Subsequent nodes receive incrementing IDs. -
namespaceResolver— Function that converts namespace URI strings to internedNamespaceIdvalues. This is typically backed by a database-wide namespace table. -
preserveWhitespace— Whentrue, whitespace-only text nodes are preserved. Whenfalse(default), they are discarded, matching the behavior ofstrip-spacein XSLT.
#Methods
#AddNode(PhoenixmlDb.Xdm.Nodes.XdmNode)
Appends a node to the flat node list and the id index in lockstep. All node creation must route through here so
stays in sync.
#CreateTextNode(String,Nullable<PhoenixmlDb.Core.NodeId>,Int32,Int32)
Creates a single text node from an already-coalesced run of character data. The caller supplies the concatenated
and the source position of the FIRST character-data event in the run (see the coalescing loop in
). The value is always non-empty by construction.
#Parse(IO.Stream,String)
Parses XML content from a
into an XDM document tree.
Parameters:
-
stream— A stream containing the XML content. The stream's encoding is auto-detected. -
documentUri— Optional document URI to assign to the resultingXdmDocument.
Returns: A ParseResult containing the document and all parsed nodes.
Exceptions:
-
XmlException— The XML content is not well-formed.
#Parse(IO.TextReader,String)
Parses XML content from a
into an XDM document tree.
Parameters:
-
textReader— A reader positioned at the start of the XML content. -
documentUri— Optional document URI to assign to the resultingXdmDocument.
Returns: A ParseResult containing the document and all parsed nodes.
Exceptions:
-
XmlException— The XML content is not well-formed.
#Parse(IO.TextReader,String,Xml.Schema.XmlSchemaSet)
Parses XML content with XSD schema validation, populating type annotations (including
xs:ID
/
xs:IDREF
) from the schema.
Parameters:
-
textReader— A reader positioned at the start of the XML content. -
documentUri— Optional document URI to assign to the resultingXdmDocument. -
schemas— The XSD schema set to validate against.
Returns: A ParseResult containing the document and all parsed nodes.
#Parse(String,String)
Parses XML content from a string into an XDM document tree.
Parameters:
-
xml— The XML content to parse. Must be well-formed XML. -
documentUri— Optional document URI to assign to the resultingXdmDocument.
Returns: A ParseResult containing the document and all parsed nodes.
Exceptions:
-
XmlException— The XML content is not well-formed.
#ResolveSchemaTypeAnnotation(Xml.XmlQualifiedName,PhoenixmlDb.Xdm.XdmTypeName)
Computes the string value of an element from its children (text + nested elements). Walks _nodes to resolve child NodeIds.
Maps an
from the XmlReader's SchemaInfo to an
suitable for
or
. Returns
when no schema type was reported, when the type is anonymous (no QualifiedName), or when the qualified name has no local part.
#Fields
| Name | Description |
|---|---|
_readerSchemaTypeProperties
|
Cached reflection accessors for the internal SchemaType property on validating readers. This property returns an XmlSchemaDatatype for DTD-validated attributes, exposing the XmlSchemaDatatype.TokenizedType needed to identify ID/IDREF/IDREFS attributes. We cache per-reader-type because different validation modes use different internal reader types (XmlValidatingReaderImpl for DTD, XsdValidatingReader for XSD). Using a single cached PropertyInfo across both fails at runtime when types mismatch.
|