Skip to main content

Module reader

Module reader 

Source
Expand description

XML Reader API (§30, §85 Phase 7).

Cursor-based streaming reader with node type, depth, attribute traversal, namespace lookup, value retrieval, validation integration.

Implements the xmlTextReader API from libxml2, which provides a cursor-based streaming interface for reading XML documents. The reader parses the entire document into a tree on the first Read() call, then walks the tree in document order (depth-first traversal) generating node events for elements, text, comments, PIs, etc.

§UPSTREAM-PARITY

The reader API is defined in libxml/xmlreader.h and libxml/xmlreader.c. Key differences from upstream:

  • The reader parses the full document on first Read rather than using a true streaming/event-driven parser. This simplifies the implementation while preserving the observable API surface.
  • Pattern-based reader operations (xmlTextReaderPreservePattern, etc.) are not yet implemented.

Structs§

XmlTextReader
XmlTextReaderLocator
Opaque locator passed to the reader error handler (upstream xmlTextReaderLocator).

Enums§

ReadState
Reader read state (xmlTextReaderReadState enum).
ReaderNodeType
Reader node types (xmlReaderTypes enum).

Constants§

XML_PARSER_SEVERITY_ERROR
XML_PARSER_SEVERITY_VALIDITY_ERROR
XML_PARSER_SEVERITY_VALIDITY_WARNING
Error severity (upstream xmlParserSeverities, reader.h).
XML_PARSER_SEVERITY_WARNING

Functions§

xmlFreeTextReader
Free a text reader.
xmlNewTextReader
Create a new text reader from an input buffer.
xmlNewTextReaderFilename
xmlTextReaderPtr xmlNewTextReaderFilename(const char *URI) — upstream xmlreader.c: creates a reader over the file, no encoding/options (R-000176: the candidate previously exported a 3-argument extension).
xmlReaderForDoc
xmlTextReaderPtr xmlReaderForDoc(const xmlChar *cur, const char *URL, const char *encoding, int options) — reader over an in-memory XML string.
xmlReaderForFd
Create a text reader from a file descriptor.
xmlReaderForFile
Create a text reader for a file.
xmlReaderForIO
Create a text reader from I/O callbacks.
xmlReaderForMemory
Create a text reader from memory.
xmlReaderNewDoc
int xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar *cur, const char *URL, const char *encoding, int options).
xmlReaderNewFd
int xmlReaderNewFd(xmlTextReaderPtr reader, int fd, const char *URL, const char *encoding, int options).
xmlReaderNewFile
int xmlReaderNewFile(xmlTextReaderPtr reader, const char *filename, const char *encoding, int options).
xmlReaderNewIO
int xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, void *ioctx, const char *URL, const char *encoding, int options).
xmlReaderNewMemory
int xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, int size, const char *URL, const char *encoding, int options).
xmlReaderNewWalker
int xmlReaderNewWalker(xmlTextReaderPtr reader, xmlDocPtr doc).
xmlReaderWalker
xmlTextReaderPtr xmlReaderWalker(xmlDocPtr doc) — reader walking an existing document tree.
xmlTextReaderAttributeCount
Get the attribute count of the current element.
xmlTextReaderBaseUri
Get the base URI of the current node.
xmlTextReaderByteConsumed
long xmlTextReaderByteConsumed(xmlTextReaderPtr reader).
xmlTextReaderClose
Close the reader, releasing the document and parser state.
xmlTextReaderConstBaseUri
const xmlChar *xmlTextReaderConstBaseUri(xmlTextReaderPtr reader) — the base URI, valid until the reader is freed (no copy).
xmlTextReaderConstEncoding
const xmlChar *xmlTextReaderConstEncoding(xmlTextReaderPtr reader).
xmlTextReaderConstLocalName
const xmlChar *xmlTextReaderConstLocalName(xmlTextReaderPtr reader).
xmlTextReaderConstName
Get a constant pointer to the name (no copy).
xmlTextReaderConstNamespaceUri
const xmlChar *xmlTextReaderConstNamespaceUri(xmlTextReaderPtr reader).
xmlTextReaderConstPrefix
const xmlChar *xmlTextReaderConstPrefix(xmlTextReaderPtr reader).
xmlTextReaderConstString
const xmlChar *xmlTextReaderConstString(xmlTextReaderPtr reader, const xmlChar *str) — the reader’s dictionary-internalized copy of str; the candidate returns str unchanged (dictionary interning is an internal detail).
xmlTextReaderConstValue
Get a constant pointer to the value (no copy).
xmlTextReaderConstXmlLang
const xmlChar *xmlTextReaderConstXmlLang(xmlTextReaderPtr reader).
xmlTextReaderConstXmlVersion
const xmlChar *xmlTextReaderConstXmlVersion(xmlTextReaderPtr reader).
xmlTextReaderCurrentDoc
Get the current document from the reader.
xmlTextReaderCurrentNode
Return the current node of the reader.
xmlTextReaderDepth
Get the depth of the current node.
xmlTextReaderExpand
Expand entity references at the current position.
xmlTextReaderGetAttribute
Get an attribute value by name.
xmlTextReaderGetAttributeNo
Get an attribute value by index.
xmlTextReaderGetAttributeNs
Get an attribute value by local name and namespace URI.
xmlTextReaderGetErrorHandler
void xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader, xmlTextReaderErrorFunc *f, void **arg).
xmlTextReaderGetLastError
const xmlError *xmlTextReaderGetLastError(xmlTextReaderPtr reader) — pointer to the reader’s embedded _xmlError (upstream returns &reader->ctxt->lastError, which is always present while the reader exists; valid until the next error is collected).
xmlTextReaderGetParserColumnNumber
Return the parser column number of the current node.
xmlTextReaderGetParserLineNumber
Return the parser line number of the current node.
xmlTextReaderGetParserProp
Get a parser property.
xmlTextReaderGetRemainder
xmlParserInputBufferPtr xmlTextReaderGetRemainder(xmlTextReaderPtr reader).
xmlTextReaderHasAttributes
Check if the current node has attributes.
xmlTextReaderHasValue
Check if the current node has a value.
xmlTextReaderIsDefault
int xmlTextReaderIsDefault(xmlTextReaderPtr reader) — whether the current attribute came from the DTD default. The candidate returns 0 for a valid reader (DTD default attribute expansion is not annotated; documented divergence), -1 for a NULL reader (upstream contract).
xmlTextReaderIsEmptyElement
Check if the current element is an empty element (no children).
xmlTextReaderIsNamespaceDecl
int xmlTextReaderIsNamespaceDecl(xmlTextReaderPtr reader) — whether the current attribute position is a namespace declaration.
xmlTextReaderIsValid
Return the validation status of the reader.
xmlTextReaderLocalName
Get the local name of the current node.
xmlTextReaderLocatorBaseURI
xmlChar *xmlTextReaderLocatorBaseURI(xmlTextReaderLocatorPtr locator).
xmlTextReaderLocatorLineNumber
int xmlTextReaderLocatorLineNumber(xmlTextReaderLocatorPtr locator).
xmlTextReaderLookupNamespace
Look up a namespace by prefix.
xmlTextReaderMoveToAttribute
Move to an attribute by name.
xmlTextReaderMoveToAttributeNo
Move to an attribute by index.
xmlTextReaderMoveToAttributeNs
int xmlTextReaderMoveToAttributeNs(xmlTextReaderPtr reader, const xmlChar *localName, const xmlChar *namespaceURI).
xmlTextReaderMoveToElement
Move the reader back to the parent element (from an attribute).
xmlTextReaderMoveToFirstAttribute
Move to the first attribute of the current element.
xmlTextReaderMoveToNextAttribute
Move to the next attribute.
xmlTextReaderName
Get the name of the current node.
xmlTextReaderNamespaceUri
Get the namespace URI of the current node.
xmlTextReaderNext
Skip to the next sibling of the current node.
xmlTextReaderNextSibling
Skip to the next sibling (same as xmlTextReaderNext).
xmlTextReaderNodeType
Get the node type of the current node.
xmlTextReaderNormalization
Return the normalization status of the reader.
xmlTextReaderPrefix
Get the prefix of the current node.
xmlTextReaderPreserve
xmlNodePtr xmlTextReaderPreserve(xmlTextReaderPtr reader) — the current node (the candidate’s reader owns the whole tree, so no separate preservation step is needed).
xmlTextReaderPreservePattern
int xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern, const xmlChar **namespaces).
xmlTextReaderPrev
Skip to the previous sibling of the current node.
xmlTextReaderQuoteChar
int xmlTextReaderQuoteChar(xmlTextReaderPtr reader).
xmlTextReaderRead
Advance the reader to the next node in document order.
xmlTextReaderReadAttributeValue
Read the value of an attribute as a text node (attribute-value mode).
xmlTextReaderReadInnerXml
Read the inner XML of the current node as a string.
xmlTextReaderReadOuterXml
Read the outer XML of the current node as a string.
xmlTextReaderReadState
Get the read state.
xmlTextReaderReadString
Read the content of the current node as a string.
xmlTextReaderRelaxNGSetSchema
int xmlTextReaderRelaxNGSetSchema(xmlTextReaderPtr reader, xmlRelaxNGPtr schema).
xmlTextReaderRelaxNGValidate
int xmlTextReaderRelaxNGValidate(xmlTextReaderPtr reader, const char *rng).
xmlTextReaderRelaxNGValidateCtxt
int xmlTextReaderRelaxNGValidateCtxt(xmlTextReaderPtr reader, xmlRelaxNGValidCtxtPtr ctxt, int options).
xmlTextReaderSchemaValidate
int xmlTextReaderSchemaValidate(xmlTextReaderPtr reader, const char *xsd) — parse xsd and validate the reader’s document.
xmlTextReaderSchemaValidateCtxt
int xmlTextReaderSchemaValidateCtxt(xmlTextReaderPtr reader, xmlSchemaValidCtxtPtr ctxt, int options).
xmlTextReaderSetErrorHandler
int xmlTextReaderSetErrorHandler(xmlTextReaderPtr reader, xmlTextReaderErrorFunc f, void *arg).
xmlTextReaderSetMaxAmplification
void xmlTextReaderSetMaxAmplification(xmlTextReaderPtr reader, unsigned maxAmpl).
xmlTextReaderSetParserProp
Set a parser property.
xmlTextReaderSetResourceLoader
void xmlTextReaderSetResourceLoader(xmlTextReaderPtr reader, xmlResourceLoader loader, void *data) — install a custom resource loader; stored on the reader and forwarded to its parser context (upstream xmlreader.c).
xmlTextReaderSetSchema
int xmlTextReaderSetSchema(xmlTextReaderPtr reader, xmlSchemaPtr schema).
xmlTextReaderSetStructuredErrorHandler
void xmlTextReaderSetStructuredErrorHandler(xmlTextReaderPtr reader, xmlStructuredErrorFunc f, void *arg).
xmlTextReaderSetup
Setup/reinitialize a reader with new input.
xmlTextReaderStandalone
Return the standalone flag of the document being read.
xmlTextReaderValue
Get the value of the current node.
xmlTextReaderXmlLang
Return the xml:lang of the current node.

Type Aliases§

xmlTextReaderErrorFunc
Reader error callback (upstream xmlTextReaderErrorFunc).