Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::xml::XMLParser Class Reference

Parses an XML document from a string. More...

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

Classes

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

Static Public Member Functions

static ParseResult< XMLDocumentParse (std::string_view str, const Options &options=Options())
 Parse an XML string with the given options.
 
static std::optional< FileOffsetRangeGetAttributeLocation (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 a string.

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

Member Function Documentation

◆ GetAttributeLocation()

std::optional< FileOffsetRange > 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 FileOffsetRange 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.
attributeNameName of the attribute to find.
Returns
std::optional<AttributeLocation> containing the start and end offsets of the attribute in the input string, or std::nullopt if the attribute was not found.

◆ 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 will ignore comments, the doctype node, and processing instructions. To enable parsing these nodes, configure the flags within Options.

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.

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