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. | |
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.
|
static |
Parse the XML attributes and get the source location of a specific attribute.
For example, for the following XML:
The SourceRange for the attr attribute should contain the substring attr="Hello, world!"
| str | XML data to parse. Will not be modified. |
| elementStartOffset | Start offset of the element in the input string, pointing at its <. |
| attributeName | Name of the attribute to find. |
elementStartOffset is unresolved or out of range, or the opening tag is malformed.
|
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.
| str | XML data to parse. Will not be modified. |
| options | Options to modify the parsing behavior. |
|
static |
Original source parser policy with any subsequently tightened document ceilings. Returns nullopt after source replacement or when the original policy is unavailable.
| document | Source-backed document whose owner may need a full reparse. |