4#ifndef _Stroika_Foundation_DataExchange_XML_DOM_h_
5#define _Stroika_Foundation_DataExchange_XML_DOM_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
12#include "Stroika/Foundation/DataExchange/BadFormatException.h"
14#include "Stroika/Foundation/DataExchange/XML/Namespace.h"
17#include "Stroika/Foundation/Execution/Exceptions.h"
21namespace Stroika::Foundation::DataExchange::XML::Providers {
25namespace Stroika::Foundation::DataExchange::XML::DOM {
27 using Traversal::Iterable;
107 using Result = variant<Node::Ptr, bool, int, double, String>;
112 template <
typename T>
113 constexpr uint8_t ResultTypeIndex_v =
static_cast<uint8_t
> (Common::VariantIndex<Result, T>);
137 optional<uint8_t> fResultTypeIndex{ResultTypeIndex_v<Node::Ptr>};
142 bool fOrdered{
false};
147 bool fSnapshot{
false};
151 nonvirtual
String ToString ()
const;
153 static inline const Options kDefaultOptions{
154 .fNamespaces = {}, .fResultTypeIndex = ResultTypeIndex_v<Node::Ptr>, .fOrdered =
false, .fSnapshot =
false};
158 template <Characters::IConvertibleToString ST>
159 Expression (ST&& e,
const Options& o = kDefaultOptions);
163 virtual ~IRep () =
default;
164 virtual String GetExpression ()
const = 0;
165 virtual Options GetOptions ()
const = 0;
183 nonvirtual
String ToString ()
const;
186 nonvirtual shared_ptr<const IRep> GetRep ()
const;
189 shared_ptr<const IRep> fRep_;
249 Ptr (
const shared_ptr<IRep>& from);
266 explicit operator bool ()
const;
271 nonvirtual
Type GetNodeType ()
const;
311 nonvirtual
void Delete ();
325 nonvirtual shared_ptr<IRep>
GetRep ()
const;
331 nonvirtual shared_ptr<IRep>
PeekRep ()
const;
339 shared_ptr<IRep> fRep_;
347 virtual ~IRep () =
default;
349 virtual const Providers::IDOMProvider* GetProvider ()
const = 0;
350 virtual bool Equals (
const IRep* rhs)
const = 0;
351 virtual Type GetNodeType ()
const = 0;
357 virtual String GetValue ()
const = 0;
359 virtual void SetValue (
const String& v) = 0;
360 virtual void DeleteNode () = 0;
361 virtual Ptr GetParentNode ()
const = 0;
368 using namespace Node;
392 Ptr (
const XPath::Result& p);
393 Ptr (
const shared_ptr<IRep>& p);
422 template <same_as<VariantValue> VV>
429 nonvirtual optional<String>
GetID ()
const;
484 template <same_as<VariantValue> VV>
485 nonvirtual
void SetValue (
const VV& v);
486 template <same_as<VariantValue> VV>
539 template <same_as<VariantValue> VV>
553 template <same_as<VariantValue> VV>
557 [[deprecated]]
Ptr AppendIfNotEmpty (
const NameWithNamespace& eltName,
const optional<String>& v)
559 return AppendIf (eltName, v == nullopt or v->empty () ? nullopt : v);
581 nonvirtual
Ptr GetParent ()
const;
617 nonvirtual
Ptr GetChildByID (
const String&
id)
const;
663 nonvirtual shared_ptr<IRep>
GetRep ()
const;
676 virtual optional<String> GetAttribute (
const NameWithNamespace& attrName)
const = 0;
677 virtual void SetAttribute (
const NameWithNamespace& attrName,
const optional<String>& v) = 0;
689 virtual Ptr InsertImportedNode (
const Node::Ptr& cloneFrom,
const Ptr& afterNode) = 0;
692 virtual Ptr GetChildElementByID (
const String&
id)
const;
727 Ptr (
const shared_ptr<IRep>& rep);
728 Ptr (
const Ptr& from) =
default;
731 Ptr& operator= (
const Ptr& rhs) =
default;
739 bool operator== (
const Ptr&)
const =
default;
740 bool operator== (nullptr_t)
const;
743 nonvirtual
bool GetStandalone ()
const;
746 nonvirtual
void SetStandalone (
bool standalone);
829 nonvirtual shared_ptr<IRep>
GetRep ()
const;
832 shared_ptr<IRep> fRep_;
855 Ptr New (
const Providers::IDOMProvider& p);
858 const Schema::Ptr& schemaToValidateAgainstWhileReading =
nullptr);
859 Ptr New (
const Providers::IDOMProvider& p,
const String& in,
860 const Schema::Ptr& schemaToValidateAgainstWhileReading =
nullptr);
861 Ptr New (
const Providers::IDOMProvider& p,
const Ptr& clone);
862#if qStroika_Foundation_DataExchange_XML_SupportDOM
867 Ptr New (
const String& in,
const Schema::Ptr& schemaToValidateAgainstWhileReading =
nullptr,
const Options& o = {});
868 Ptr New (
const Ptr& clone,
const Options& o = {});
874 virtual ~IRep () =
default;
875 virtual const Providers::IDOMProvider* GetProvider ()
const = 0;
876 virtual bool GetStandalone ()
const = 0;
877 virtual void SetStandalone (
bool standalone) = 0;
878 virtual Element::Ptr ReplaceRootElement (
const NameWithNamespace& newEltName,
const optional<String>& namespacePrefix) = 0;
880 virtual Iterable<Node::Ptr> GetChildren ()
const = 0;
881 virtual void Validate (
const Schema::Ptr& schema)
const = 0;
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Document::Ptr is create with Document::New, and is a smart pointer to a DOM document object.
nonvirtual void Validate(const Schema::Ptr &schema) const
nonvirtual void Write(const Streams::OutputStream::Ptr< byte > &to, const SerializationOptions &options={}) const
The document as XML: to a byte stream as UTF-8, with no byte order mark - or as a String.
nonvirtual Iterable< Node::Ptr > GetChildren() const
nonvirtual Traversal::Iterable< Element::Ptr > LookupElements(const XPath::Expression &e) const
shorthand for GetRootElement ().LookupElements (e) - so requires root element exists
nonvirtual shared_ptr< IRep > GetRep() const
nonvirtual Element::Ptr GetRootElement() const
always returns Node of eElement or return nullptr if none
nonvirtual Element::Ptr LookupOneElement(const XPath::Expression &e) const
shorthand for GetRootElement ().LookupOneElement (e) - so requires root element exists
nonvirtual Traversal::Iterable< XPath::Result > Lookup(const XPath::Expression &e) const
shorthand for GetRootElement ().Lookup (e) - so requires root element exists
nonvirtual Element::Ptr ReplaceRootElement(const NameWithNamespace &newEltName, const optional< String > &namespacePrefix=nullopt) const
Make this the document's root element - and say HOW its namespace is declared on it,...
nonvirtual Node::Ptr LookupOneNode(const XPath::Expression &e) const
nonvirtual shared_ptr< IRep > PeekRep() const
return the associated shared_ptr (can be nullptr)
nonvirtual optional< String > GetID() const
nonvirtual Ptr ImportNode(const Node::Ptr &cloneFrom, const Node::Ptr &afterNode)
... placed after afterNode, or first if nullptr
nonvirtual optional< URI > GetDefaultNamespace() const
nonvirtual Traversal::Iterable< Element::Ptr > LookupElements(const XPath::Expression &e) const
nonvirtual Ptr Append(const NameWithNamespace &eltName)
nonvirtual Element::Ptr LookupOneElement(const XPath::Expression &e) const
nonvirtual Traversal::Iterable< XPath::Result > Lookup(const XPath::Expression &e) const
nonvirtual Ptr AppendIf(const NameWithNamespace &eltName, const optional< String > &v)
Trivial wrapper on AppendElement, but if v is missing then this is a no-op.
nonvirtual void SetDefaultNamespace(const optional< URI > defaultNS=nullopt)
Sets the xmlns attribute of this element.
nonvirtual void SetAttribute(const NameWithNamespace &attrName, const optional< String > &v)
nonvirtual optional< String > GetAttribute(const NameWithNamespace &attrName) const
nonvirtual Ptr Insert(const NameWithNamespace &eltName, const Node::Ptr &afterNode)
Insert Element (after argument node) inside of this 'Element'.
nonvirtual shared_ptr< IRep > GetRep() const
return the associated shared_ptr (cannot be nullptr)
nonvirtual Traversal::Iterable< String > GetValues(const XPath::Expression &e) const
nonvirtual Ptr ImportNode(const Node::Ptr &cloneFrom)
Append a deep CLONE of 'cloneFrom' - an element of any document - to this element's children.
nonvirtual bool HasAttribute(const NameWithNamespace &attrName) const
Node::Ptr is a smart pointer to a Node::IRep.
nonvirtual Ptr GetParentNode() const
nonvirtual void SetValue(const String &v)
nonvirtual NameWithNamespace GetName() const
nonvirtual void SetName(const NameWithNamespace &name)
nonvirtual bool operator==(const Ptr &rhs) const
nonvirtual shared_ptr< IRep > PeekRep() const
return the associated shared_ptr (can be nullptr)
nonvirtual String GetValue() const
nonvirtual shared_ptr< IRep > GetRep() const
return the associated shared_ptr (cannot be nullptr)
nonvirtual String GetExpression() const
nonvirtual Options GetOptions() const
Exception<> is a replacement (subclass) for any std c++ exception class (e.g. the default 'std::excep...
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
virtual Ptr AppendImportedNode(const Node::Ptr &cloneFrom)=0
virtual Ptr InsertElement(const NameWithNamespace &eltName, const Ptr &afterNode)=0
optional< unsigned int > fIndent
An element's or attribute's name (local-name, not including a prefix), plus the namespace that name i...
used to specify default namespace, and any n: prefixes applicable to elements.
How XML is read and written - for now, with which provider - taken last by each XML function (DOM::Do...