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"
15#include "Stroika/Foundation/Execution/Exceptions.h"
19namespace Stroika::Foundation::DataExchange::XML::Schema {
22namespace Stroika::Foundation::DataExchange::XML::Providers {
26namespace Stroika::Foundation::DataExchange::XML::DOM {
28 using Traversal::Iterable;
50 bool fPrettyPrint{
false};
51 optional<unsigned int> fIndent{};
87 using Result = variant<Node::Ptr, bool, int, double, String>;
93 constexpr uint8_t ResultTypeIndex_v =
static_cast<uint8_t
> (Common::VariantIndex<Result, T>);
117 optional<uint8_t> fResultTypeIndex{ResultTypeIndex_v<Node::Ptr>};
122 bool fOrdered{
false};
127 bool fSnapshot{
false};
131 nonvirtual
String ToString ()
const;
133 static inline const Options kDefaultOptions{
134 .fNamespaces = {}, .fResultTypeIndex = ResultTypeIndex_v<Node::Ptr>, .fOrdered =
false, .fSnapshot =
false};
138 template <Characters::IConvertibleToString ST>
139 Expression (ST&& e,
const Options& o = kDefaultOptions);
143 virtual ~IRep () =
default;
144 virtual String GetExpression ()
const = 0;
145 virtual Options GetOptions ()
const = 0;
163 nonvirtual
String ToString ()
const;
166 nonvirtual shared_ptr<const IRep> GetRep ()
const;
169 shared_ptr<const IRep> fRep_;
216 Ptr (
const shared_ptr<IRep>& from);
233 explicit operator bool ()
const;
238 nonvirtual
Type GetNodeType ()
const;
278 nonvirtual
void Delete ();
292 nonvirtual shared_ptr<IRep>
GetRep ()
const;
298 nonvirtual shared_ptr<IRep>
PeekRep ()
const;
306 shared_ptr<IRep> fRep_;
314 virtual ~IRep () =
default;
316 virtual const Providers::IDOMProvider* GetProvider ()
const = 0;
317 virtual bool Equals (
const IRep* rhs)
const = 0;
318 virtual Type GetNodeType ()
const = 0;
324 virtual String GetValue ()
const = 0;
326 virtual void SetValue (
const String& v) = 0;
327 virtual void DeleteNode () = 0;
328 virtual Ptr GetParentNode ()
const = 0;
335 using namespace Node;
359 Ptr (
const XPath::Result& p);
360 Ptr (
const shared_ptr<IRep>& p);
389 template <same_as<VariantValue> VV>
396 nonvirtual optional<String>
GetID ()
const;
451 template <same_as<VariantValue> VV>
452 nonvirtual
void SetValue (
const VV& v);
453 template <same_as<VariantValue> VV>
476 template <same_as<VariantValue> VV>
490 template <same_as<VariantValue> VV>
494 [[deprecated]]
Ptr AppendIfNotEmpty (
const NameWithNamespace& eltName,
const optional<String>& v)
496 return AppendIf (eltName, v == nullopt or v->empty () ? nullopt : v);
518 nonvirtual
Ptr GetParent ()
const;
554 nonvirtual
Ptr GetChildByID (
const String&
id)
const;
600 nonvirtual shared_ptr<IRep>
GetRep ()
const;
613 virtual optional<String> GetAttribute (
const NameWithNamespace& attrName)
const = 0;
614 virtual void SetAttribute (
const NameWithNamespace& attrName,
const optional<String>& v) = 0;
622 virtual Ptr GetChildElementByID (
const String&
id)
const;
657 Ptr (
const shared_ptr<IRep>& rep);
658 Ptr (
const Ptr& from) =
default;
661 Ptr& operator= (
const Ptr& rhs) =
default;
669 bool operator== (
const Ptr&)
const =
default;
670 bool operator== (nullptr_t)
const;
673 nonvirtual
bool GetStandalone ()
const;
676 nonvirtual
void SetStandalone (
bool standalone);
739 nonvirtual shared_ptr<IRep>
GetRep ()
const;
742 shared_ptr<IRep> fRep_;
759 Ptr New (
const Providers::IDOMProvider& p);
763 Ptr New (
const Providers::IDOMProvider& p,
const String& in);
764 Ptr New (
const Providers::IDOMProvider& p,
const String& in,
const Schema::Ptr& schemaToValidateAgainstWhileReading);
765 Ptr New (
const Providers::IDOMProvider& p,
const Ptr& clone);
766#if qStroika_Foundation_DataExchange_XML_SupportDOM
773 Ptr New (
const Ptr& clone);
779 virtual ~IRep () =
default;
780 virtual const Providers::IDOMProvider* GetProvider ()
const = 0;
781 virtual bool GetStandalone ()
const = 0;
782 virtual void SetStandalone (
bool standalone) = 0;
786 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 Element::Ptr ReplaceRootElement(const NameWithNamespace &newEltName, bool childrenInheritNS=true) const
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 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 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 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
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 InsertElement(const NameWithNamespace &eltName, const Ptr &afterNode)=0
used to specify default namespace, and any n: prefixes applicable to elements.