Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::xml::XMLParser Class Reference

Parses an XML document from UTF-8 bytes. More...

#include "donner/base/xml/XMLParser.h"

Classes

struct  Options
 Options to modify the parsing behavior. More...

Static Public Member Functions

static ParseResult< XMLDocument > Parse (std::string_view str, const Options &options=Options())
 Parse an XML string with the given options.
static std::optional< Options > SourceOptions (const XMLDocument &document)
 Original source parser policy with any subsequently tightened document ceilings. Returns nullopt after source replacement or when the original policy is unavailable.
static std::optional< SourceRange > GetAttributeLocation (std::string_view str, FileOffset elementStartOffset, const XMLQualifiedNameRef &attributeName)
 Parse the XML attributes and get the source location of a specific attribute.

Detailed Description

Parses an XML document from UTF-8 bytes.

This byte API does not transcode other encodings. An encoding declaration, when present, must name UTF-8 (case-insensitively); other declared encodings return an unsupported-input error. Transcode legacy input and update or remove its encoding declaration before calling Parse. Raw UTF-8 and XML character validation precedes declaration parsing, so invalid bytes report that error before an unsupported encoding declaration. Malformed UTF-8 is rejected in every context, including names; a correctly encoded Unicode replacement character remains valid.

The document tree will remain valid as long as the returned XMLDocument is alive.

Member Function Documentation

◆ GetAttributeLocation()

std::optional< SourceRange > donner::xml::XMLParser::GetAttributeLocation ( std::string_view str,
FileOffset elementStartOffset,
const XMLQualifiedNameRef & attributeName )
static

Parse the XML attributes and get the source location of a specific attribute.

For example, for the following XML:

<root>
<child attr="Hello, world!">
</root>

The SourceRange for the attr attribute should contain the substring attr="Hello, world!"

Parameters
strXML data to parse. Will not be modified.
elementStartOffsetStart offset of the element in the input string, pointing at its <.
attributeNameName of the attribute to find.
Returns
The source range of the attribute in the input string, or std::nullopt if the attribute was not found, elementStartOffset is unresolved or out of range, or the opening tag is malformed.

◆ Parse()

ParseResult< XMLDocument > donner::xml::XMLParser::Parse ( std::string_view str,
const Options & options = Options() )
static

Parse an XML string with the given options.

By default, the parser keeps the doctype node but ignores comments and processing instructions. To change which of these nodes are parsed, configure the flags within Options.

The input-size limit is checked first, then raw UTF-8 and XML characters are validated before allocating parser-owned source and tree state. Ignored comments and processing instructions are validated too. Invalid input returns an error without a document.

The document tree will remain valid as long as the returned XMLDocument is alive.

Parameters
strXML data to parse. Will not be modified.
optionsOptions to modify the parsing behavior.
Returns
ParseResult containing the parsed XMLDocument, or an error if parsing failed.

◆ SourceOptions()

std::optional< Options > donner::xml::XMLParser::SourceOptions ( const XMLDocument & document)
static

Original source parser policy with any subsequently tightened document ceilings. Returns nullopt after source replacement or when the original policy is unavailable.

Parameters
documentSource-backed document whose owner may need a full reparse.

The documentation for this class was generated from the following file: