2#include <pugixml/pugixml.hpp>
3#include <string/sstringw.h>
4#include <string/strcpcvt.h>
28 if(!
attr)
return NULL;
30 return pDoc->toIXmlAttr(
attr.internal_object());
35 return _attr.internal_object();
60 return _attr.get_userdata();
65 pugi::xml_attribute
attr = _attr.next_attribute();
66 return toIXmlAttr(
attr);
71 pugi::xml_attribute
attr = _attr.previous_attribute();
72 return toIXmlAttr(
attr);
75SXmlAttr::operator bool()
const
77 return !_attr.empty();
97 return _attr.as_string(def);
102 return _attr.as_int(def);
107 return _attr.as_uint(def);
112 return _attr.as_double(def);
117 return _attr.as_float(def);
122 return _attr.as_bool(def);
127 return _attr.set_name(rhs);
132 return _attr.set_value(rhs);
137 return _attr.set_value(rhs);
142 return _attr.set_value(rhs);
147 return _attr.set_value(rhs);
152 return _attr.set_value(rhs);
157 return _attr.set_value(rhs);
162 return _attr.set_value(rhs,precision);
167 return _attr.set_value(rhs);
172 return _attr.set_value(rhs,precision);
177 return _attr.set_value(rhs);
240 pugi::xml_writer_buff writer;
241 _node.print(writer, L
"\t", pugi::format_default,
sizeof(
wchar_t) == 2 ? pugi::encoding_utf16 : pugi::encoding_utf32);
242 out->Assign2(writer.buffer(), writer.size());
247 return _node.internal_object();
252 return _node.empty();
262 return _node.value();
267 return _node.text().get();
272 return _node.set_userdata(data);
277 return _node.get_userdata();
282 pugi::xml_attribute
attr = _node.attribute(
name,!!bCaseSensitive);
283 return SXmlAttr::toIXmlAttr(
attr);
288 pugi::xml_attribute
attr = _node.first_attribute();
289 return SXmlAttr::toIXmlAttr(
attr);
294 pugi::xml_attribute
attr = _node.last_attribute();
295 return SXmlAttr::toIXmlAttr(
attr);
300 pugi::xml_node node = _node.child(
name,!!bCaseSensitive);
301 return toIXmlNode(node);
306 pugi::xml_node node = _node.first_child();
307 return toIXmlNode(node);
312 pugi::xml_node node = _node.last_child();
313 return toIXmlNode(node);
318 pugi::xml_node node = _node.next_sibling();
319 return toIXmlNode(node);
324 pugi::xml_node node = _node.previous_sibling();
325 return toIXmlNode(node);
330 pugi::xml_node node = _node.next_sibling(
name,!!bCaseSensitive);
331 return toIXmlNode(node);
336 pugi::xml_node node = _node.previous_sibling(
name,!!bCaseSensitive);
337 return toIXmlNode(node);
340IXmlNode * SXmlNode::toIXmlNode(pugi::xml_node node)
342 if(!node)
return NULL;
344 return pDoc->toIXmlNode(node.internal_object());
348SXmlNode::operator bool()
const
350 return !_node.empty();
355 return _node.empty();
360 return (XmlNodeType)_node.type();
370 return _node.value();
375 return _node.first_attribute();
380 return _node.last_attribute();
430 return _node.attribute(
name,bCaseSensitive);
435 return _node.attribute(
name,hint._attr,bCaseSensitive);
440 return _node.child_value();
445 return _node.child_value(
name,bCaseSensitive);
455 return _node.set_value(rhs);
460 return _node.append_attribute(
name);
465 return _node.prepend_attribute(
name);
470 return _node.insert_attribute_after(
name,
attr._attr);
475 return _node.insert_attribute_before(
name,
attr._attr);
480 return _node.append_copy(proto._attr);
485 return _node.append_copy(proto._node);
490 return _node.prepend_copy(proto._attr);
495 return _node.prepend_copy(proto._node);
500 return _node.insert_copy_after(proto._attr,
attr._attr);
505 return _node.insert_copy_after(proto._node,node._node);
510 return _node.insert_copy_before(proto._attr,
attr._attr);
515 return _node.insert_move_before(proto._node,node._node);
585 return _node.remove_attribute(
name);
590 return _node.remove_attributes();
595 return _node.remove_child(n._node);
600 return _node.remove_child(
name);
605 return _node.remove_children();
613 m_attrMap =
new AttrMap;
614 m_nodeMap =
new NodeMap;
615 _doc =
new pugi::xml_document;
616 _doc->set_extra_data(
this);
629 return SXmlNode::toIXmlNode(*_doc);
632BOOL
SXmlDoc::SaveFileW(THIS_
const wchar_t* path,
const wchar_t* indent ,
unsigned int flags, XmlEncoding encoding) SCONST
634 return _doc->save_file(path,indent,flags,(pugi::xml_encoding)encoding);
637BOOL
SXmlDoc::SaveFileA(THIS_
const char* path,
const wchar_t* indent ,
unsigned int flags, XmlEncoding encoding) SCONST
639 SStringW strPath = S_CA2W(path,CP_UTF8);
650 _result = _doc->load_buffer_inplace_own(contents,size,options,(pugi::xml_encoding)encoding);
656 _result = _doc->load_buffer_inplace(contents,size,options,(pugi::xml_encoding)encoding);
660BOOL
SXmlDoc::LoadBuffer(THIS_
const void* contents,
size_t size,
unsigned int options , XmlEncoding encoding)
662 _result = _doc->load_buffer(contents,size,options,(pugi::xml_encoding)encoding);
668 _result = _doc->load_file(path,options,(pugi::xml_encoding)encoding);
674 SStringW strPath = S_CA2W(path,CP_UTF8);
680 _result = _doc->load_string(contents,options);
687 pResult->status = (XmlStatus)_result.status;
688 pResult->offset = _result.offset;
689 pResult->encoding = (XmlEncoding)_result.encoding;
694 _doc->reset(*(pugi::xml_document*)proto->GetPrivPtr());
710 _result = _doc->load_string(contents,options);
716 _result = _doc->load_file(path,options,(pugi::xml_encoding)encoding);
722 _result = _doc->load_file(path,options,(pugi::xml_encoding)encoding);
728 _result = _doc->load_buffer(contents,size,options,(pugi::xml_encoding)encoding);
734 _result = _doc->load_buffer_inplace(contents,size,options,(pugi::xml_encoding)encoding);
740 _result = _doc->load_buffer_inplace_own(contents,size,options,(pugi::xml_encoding)encoding);
744bool SXmlDoc::save_file(
const char* path,
const wchar_t* indent ,
unsigned int flags , XmlEncoding encoding )
const
746 return _doc->save_file(path,indent,flags,(pugi::xml_encoding)encoding);
749bool SXmlDoc::save_file(
const wchar_t* path,
const wchar_t* indent ,
unsigned int flags , XmlEncoding encoding )
const
751 return _doc->save_file(path,indent,flags,(pugi::xml_encoding)encoding);
756 return SXmlNode(*(pugi::xml_node*)_doc);
761 pugi::xml_parse_result res;
762 res.status = (pugi::xml_parse_status)status;
763 return res.description();
766IXmlAttr * SXmlDoc::toIXmlAttr(pugi::xml_attribute_struct *pAttr)
768 AttrMap::CPair *pair = m_attrMap->Lookup(pAttr);
770 return pair->m_value;
772 m_attrMap->SetAt(pAttr,pRet);
776IXmlNode * SXmlDoc::toIXmlNode(pugi::xml_node_struct* pNode)
778 NodeMap::CPair *pair = m_nodeMap->Lookup(pNode);
780 return pair->m_value;
781 SXmlNode *pRet =
new SXmlNode(pNode);
782 m_nodeMap->SetAt(pNode,pRet);
786void SXmlDoc::clearMap()
789 SPOSITION pos = m_attrMap->GetStartPosition();
791 SXmlAttr *pAttr = m_attrMap->GetNextValue(pos);
794 m_attrMap->RemoveAll();
797 SPOSITION pos = m_nodeMap->GetStartPosition();
799 SXmlNode *pNode = m_nodeMap->GetNextValue(pos);
802 m_nodeMap->RemoveAll();
A class representing an ASCII string.
const wchar_t * c_str() SCONST
Retrieves a C-style string representation of the string.
Class representing an XML attribute.
const wchar_t * Value() SCONST OVERRIDE
Gets the attribute value.
float as_float(float def=0) const
Converts the attribute value to a float.
SXmlAttr next_attribute() const
Gets the next attribute in the attribute list of the parent node.
SXmlAttr(pugi::xml_attribute attr)
Constructor for SXmlAttr.
float AsFloat(float def=0.0f) OVERRIDE
Converts the attribute value to a float.
IXmlAttr * Prev() OVERRIDE
Gets the previous attribute in the attribute list of the parent node.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the attribute.
const wchar_t * Name() SCONST OVERRIDE
Gets the attribute name.
int AsInt(int def=0) OVERRIDE
Converts the attribute value to an integer.
int as_int(int def=0) const
Converts the attribute value to an integer.
int get_userdata() SCONST OVERRIDE
Gets user data for the attribute.
bool set_value(const wchar_t *rhs)
Sets the attribute value.
bool set_name(const wchar_t *rhs)
Sets the attribute name.
double AsDouble(double def=0.0) OVERRIDE
Converts the attribute value to a double.
const wchar_t * name() const
Gets the attribute name.
BOOL Empty() SCONST OVERRIDE
Checks if the attribute is empty.
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
unsigned int as_uint(unsigned int def=0) const
Converts the attribute value to an unsigned integer.
bool as_bool(bool def=false) const
Converts the attribute value to a boolean.
IXmlAttr * Next() OVERRIDE
Gets the next attribute in the attribute list of the parent node.
double as_double(double def=0) const
Converts the attribute value to a double.
SXmlAttr previous_attribute() const
Gets the previous attribute in the attribute list of the parent node.
unsigned int AsUint(int def=0) OVERRIDE
Converts the attribute value to an unsigned integer.
LPVOID GetPrivPtr() SCONST OVERRIDE
Gets the private data pointer.
bool empty() const
Checks if the attribute is empty.
const wchar_t * value() const
Gets the attribute value.
BOOL AsBool(BOOL def=FALSE) OVERRIDE
Converts the attribute value to a boolean.
Implementation of IXmlDoc.
IXmlNode * Root() SCONST OVERRIDE
Retrieves the root node of the document.
bool load_buffer_inplace(void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer using in-place parsing.
void Copy(const IXmlDoc *proto) OVERRIDE
Copies the contents of another document into this document.
BOOL LoadBufferInplaceOwn(void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer using in-place parsing with automatic buffer management.
bool load_buffer_inplace_own(void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer using in-place parsing with automatic buffer management.
SXmlDoc()
Constructor for SXmlDoc.
BOOL LoadFileA(const char *path, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a file (ANSI version).
bool save_file(const char *path, const wchar_t *indent=L"\t", unsigned int flags=xml_parse_default, XmlEncoding encoding=enc_auto) const
Saves the XML document to a file (ANSI version).
static const char * GetErrDesc(XmlStatus status)
Retrieves the error description for a given XML status.
void GetParseResult(XmlParseResult *pResult) SCONST OVERRIDE
Retrieves the result of the last parsing operation.
~SXmlDoc()
Destructor for SXmlDoc.
SXmlNode root() const
Retrieves the root node of the document.
BOOL SaveFileW(const wchar_t *path, const wchar_t *indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE
Saves the XML document to a file (Unicode version).
BOOL LoadString(const wchar_t *contents, unsigned int options) OVERRIDE
Loads the document from a zero-terminated string.
BOOL LoadFileW(const wchar_t *path, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a file (Unicode version).
BOOL SaveFileA(const char *path, const wchar_t *indent, unsigned int flags, XmlEncoding encoding) SCONST OVERRIDE
Saves the XML document to a file (ANSI version).
BOOL LoadBufferInplace(void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer using in-place parsing.
bool load_string(const wchar_t *contents, unsigned int options=xml_parse_default)
Loads the document from a zero-terminated string.
BOOL LoadBuffer(const void *contents, size_t size, unsigned int options, XmlEncoding encoding) OVERRIDE
Loads the document from a buffer.
void Reset() OVERRIDE
Resets the document, removing all nodes.
void SaveBinary(FILE *f) SCONST OVERRIDE
Saves the XML document to a writer.
bool load_buffer(const void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer.
LPVOID GetPrivPtr() SCONST OVERRIDE
Retrieves a private pointer associated with the document.
bool load_file(const char *path, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a file (ANSI version).
SXmlAttr insert_copy_before(const SXmlAttr &proto, const SXmlAttr &attr)
Inserts a copy of the specified attribute before the specified attribute.
SXmlNode next_sibling() const
Gets the next sibling node in the children list of the parent node.
IXmlNode * PrevSibling2(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets the previous sibling node by name.
LPVOID GetPrivPtr() SCONST OVERRIDE
Gets the private data pointer.
SXmlAttr first_attribute() const
Gets the first attribute of the node.
SXmlNode parent() const
Gets the parent node of the node.
SXmlAttr insert_attribute_before(const wchar_t *name, const SXmlAttr &attr)
Inserts an attribute with the specified name before the specified attribute.
IXmlAttr * LastAttribute() SCONST OVERRIDE
Gets the last attribute in the attribute list.
SXmlNode previous_sibling() const
Gets the previous sibling node in the children list of the parent node.
SXmlNode first_child() const
Gets the first child node of the node.
SXmlAttr append_copy(const SXmlAttr &proto)
Adds a copy of the specified attribute.
const wchar_t * Name() SCONST OVERRIDE
Gets the node name.
void ToString(IStringW *out) SCONST OVERRIDE
Converts the node to a string representation.
const wchar_t * Value() SCONST OVERRIDE
Gets the node value.
IXmlAttr * FirstAttribute() SCONST OVERRIDE
Gets the first attribute in the attribute list.
bool remove_attribute(const SXmlAttr &a)
Removes the specified attribute.
IXmlNode * NextSibling2(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets the next sibling node by name.
bool set_value(const wchar_t *rhs)
Sets the value of the node.
const wchar_t * name() const
Gets the name of the node.
SXmlNode last_child() const
Gets the last child node of the node.
SXmlNode insert_move_after(const SXmlNode &moved, const SXmlNode &node)
Inserts the specified node to become a child of this node after the specified node.
bool set_name(const wchar_t *rhs)
Sets the name of the node.
bool remove_children()
Removes all child nodes from the node.
const wchar_t * child_value() const
Gets the child value of the current node.
SXmlNode append_move(const SXmlNode &moved)
Moves the specified node to become a child of this node.
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
SXmlNode insert_child_before(XmlNodeType type, const SXmlNode &node)
Inserts a child node with the specified type before the specified node.
SXmlAttr append_attribute(const wchar_t *name)
Adds an attribute with the specified name.
SXmlNode prepend_child(XmlNodeType type=node_element)
Prepends a child node with the specified type.
int get_userdata() SCONST OVERRIDE
Gets user data for the node.
SXmlAttr last_attribute() const
Gets the last attribute of the node.
bool empty() const
Checks if the node is empty.
SXmlNode root() const
Gets the root node of the DOM tree this node belongs to.
IXmlNode * NextSibling() SCONST OVERRIDE
Gets the next sibling node.
XmlNodeType type() const
Gets the type of the node.
IXmlNode * PrevSibling() SCONST OVERRIDE
Gets the previous sibling node.
bool remove_child(const SXmlNode &n)
Removes the specified child node.
IXmlNode * Child(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets a child node by name.
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
IXmlAttr * Attribute(const wchar_t *name, BOOL bCaseSensitive) SCONST OVERRIDE
Gets an attribute by name.
SXmlAttr insert_attribute_after(const wchar_t *name, const SXmlAttr &attr)
Inserts an attribute with the specified name after the specified attribute.
SXmlAttr prepend_attribute(const wchar_t *name)
Prepends an attribute with the specified name.
SXmlNode insert_child_after(XmlNodeType type, const SXmlNode &node)
Inserts a child node with the specified type after the specified node.
const wchar_t * value() const
Gets the value of the node.
bool remove_attributes()
Removes all attributes from the node.
IXmlNode * LastChild() SCONST OVERRIDE
Gets the last child node.
SXmlNode insert_move_before(const SXmlNode &moved, const SXmlNode &node)
Inserts the specified node to become a child of this node before the specified node.
IXmlNode * FirstChild() SCONST OVERRIDE
Gets the first child node.
SXmlAttr prepend_copy(const SXmlAttr &proto)
Prepends a copy of the specified attribute.
SXmlAttr insert_copy_after(const SXmlAttr &proto, const SXmlAttr &attr)
Inserts a copy of the specified attribute after the specified attribute.
const wchar_t * Text() SCONST OVERRIDE
Gets the node text.
SXmlNode prepend_move(const SXmlNode &moved)
Prepends the specified node to become a child of this node.
SXmlNode append_child(XmlNodeType type=node_element)
Adds a child node with the specified type.
BOOL Empty() SCONST OVERRIDE
Checks if the node is empty.
SXmlNode(pugi::xml_node node)
Constructor for SXmlNode.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
Interface for XML attributes.
BOOL set_userdata(int data) PURE
Sets user-defined data associated with the attribute.
Interface for XML Document.
Bitfield structure for font style attributes.