X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FKM_xml.h;h=80db74babd9d729c009229390900e032aa63d606;hb=5584493c50cfa0541398527741253a0db8cdbf18;hp=31f506471cabacffe1e714a224e0590b1db172e9;hpb=3a3aa48a5a4f7324a9e4c2273d0747d7f58a2813;p=asdcplib.git diff --git a/src/KM_xml.h b/src/KM_xml.h index 31f5064..80db74b 100644 --- a/src/KM_xml.h +++ b/src/KM_xml.h @@ -1,5 +1,5 @@ /* -Copyright (c) 2005-2006, John Hurst +Copyright (c) 2005-2011, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -41,6 +41,9 @@ namespace Kumu { class XMLElement; + // Return true if the given string contains an XML document (or the start of one). + bool StringIsXML(const char* document, ui32_t len = 0); + // struct NVPair { @@ -74,6 +77,10 @@ namespace Kumu // class XMLElement { + KM_NO_COPY_CONSTRUCT(XMLElement); + XMLElement(); + + protected: AttributeList m_AttrList; ElementList m_ChildList; const XMLNamespace* m_Namespace; @@ -82,9 +89,6 @@ namespace Kumu std::string m_Name; std::string m_Body; - KM_NO_COPY_CONSTRUCT(XMLElement); - XMLElement(); - public: XMLElement(const char* name); ~XMLElement(); @@ -92,13 +96,17 @@ namespace Kumu inline const XMLNamespace* Namespace() const { return m_Namespace; } inline void SetNamespace(const XMLNamespace* ns) { assert(ns); m_Namespace = ns; } + bool ParseString(const char* document, ui32_t doc_len); + bool ParseString(const ByteString& document); bool ParseString(const std::string& document); - bool TestString(const char* document, ui32_t len = 0); // building void SetName(const char* name); + void SetBody(const std::string& value); void AppendBody(const std::string& value); void SetAttr(const char* name, const char* value); + void SetAttr(const char* name, const std::string& value) { SetAttr(name, value.c_str()); } + XMLElement* AddChild(XMLElement* element); XMLElement* AddChild(const char* name); XMLElement* AddChildWithContent(const char* name, const char* value); XMLElement* AddChildWithContent(const char* name, const std::string& value); @@ -108,12 +116,21 @@ namespace Kumu void RenderElement(std::string& outbuf, ui32_t depth) const; // querying - inline const std::string& GetBody() const { return m_Body; } - const char* GetAttrWithName(const char* name) const; - XMLElement* GetChildWithName(const char* name) const; + inline const std::string& GetBody() const { return m_Body; } + inline const ElementList& GetChildren() const { return m_ChildList; } + inline const std::string& GetName() const { return m_Name; } + inline const AttributeList& GetAttributes() const { return m_AttrList; } + const char* GetAttrWithName(const char* name) const; + XMLElement* GetChildWithName(const char* name) const; const ElementList& GetChildrenWithName(const char* name, ElementList& outList) const; - bool HasName(const char* name) const; - + bool HasName(const char* name) const; + + // altering + void DeleteAttributes(); + void DeleteAttrWithName(const char* name); + void DeleteChildren(); + void DeleteChild(const XMLElement* element); + void ForgetChild(const XMLElement* element); }; } // namespace Kumu