5std::shared_ptr<const XmlDocument>
XmlDocument::load(
const std::string& path, std::string& error)
8 if (!reader.
open(path)) {
14 error =
"No XML rows were parsed";
17 return from_rows(std::move(*rows), error);
24 error =
"Rows do not use the XML node layout";
30 if (!
forest->index().preorder()) {
31 error =
"XML rows are not in document order";
40 const auto& index =
m_forest->index();
41 for (
size_t row = 0; row < rows.size(); row += index.subtree_size(row)) {
42 const auto source = rows.at(row);
43 if (source && source->text(
"kind") == std::string_view(
"element"))
52 if (row >= rows.size())
54 const auto source = rows.at(
static_cast<size_t>(row));
55 if (!source || source->text(
"kind") != std::string_view(
"element"))
std::string get_last_error() const override
Get the last error message.
std::shared_ptr< const Kakshya::CompositeForest > m_forest
std::optional< XmlElementView > root_element() const noexcept
Borrow the document root element.
std::optional< XmlElementView > element_at(uint64_t row) const noexcept
Borrow an element by its row index.
static std::shared_ptr< const XmlDocument > from_rows(Kakshya::CompositeArray rows, std::string &error)
Take ownership of rows in the XML node layout.
XmlDocument(std::shared_ptr< const Kakshya::CompositeForest > forest) noexcept
const Kakshya::CompositeForest & forest() const noexcept
The rows together with their parent index.
static std::shared_ptr< const XmlDocument > load(const std::string &path, std::string &error)
Parse a file into an owning document.
Borrowed XML element with named attributes and immediate child elements.
std::optional< Kakshya::CompositeArray > take_rows()
Move the parsed rows out and close the reader.
bool open(const std::string &filepath, FileReadOptions options=FileReadOptions::ALL) override
Parse an XML file and establish the fixed node layout.
Read an XML document into preorder Composite rows.
const CompositeLayout & layout() const noexcept
Finalized layout shared by all elements.
Owns a sequence of values that share a CompositeLayout.
static std::shared_ptr< const CompositeForest > build(CompositeArray rows, std::string_view parent_field, std::string &error, uint64_t *error_row=nullptr)
Index rows and take ownership of them.
bool same_structure(const CompositeLayout &other) const noexcept
Compare declared field names, kinds, and nested layouts.
Kakshya::CompositeLayout xml_composite_layout()
Composite row layout used by the XML reader and writer.