Samchon Framework for CPP
1.0.0
|
XML is a class representing xml object. More...
#include <XML.hpp>
Public Member Functions | |
XML () | |
Default Constructor. More... | |
XML (const XML &) | |
Copy Constructor. More... | |
XML (XML &&) | |
Move Constructor. More... | |
XML (WeakString) | |
Constructor by string. More... | |
void | push_back (const WeakString &) |
Add children xml objects by string representing them. More... | |
void | push_back (const std::shared_ptr< XML >) |
Add children xml. More... | |
void | addAllProperty (const std::shared_ptr< XML >) |
Add all properties from another XML. More... | |
void | setTag (const std::string &) |
Set tag (identifier) of the XML. More... | |
template<typename T > | |
void | setValue (const T &val) |
Set value of the XML. More... | |
template<typename T > | |
void | setProperty (const std::string &key, const T &val) |
Set a property with its key. More... | |
void | eraseProperty (const std::string &) |
Erase a property by its key. More... | |
void | clearProperties () |
Remove all properties in the XML. More... | |
auto | getTag () const -> std::string |
Get key; identifer of the XML. More... | |
template<class T = std::string> | |
auto | getValue () const -> T |
Get value of the XML. More... | |
template<class T = std::string> | |
auto | getProperty (const std::string &key) const -> T |
Get property. More... | |
auto | hasProperty (const std::string &) const -> bool |
Test wheter a property exists or not. More... | |
auto | getPropertyMap () const -> const HashMap< std::string, std::string > & |
Get propertyMap. More... | |
auto | toString (size_t level=0) const -> std::string |
Get the string content. More... | |
![]() | |
auto | has (const std::string &key) const -> bool |
Whether have the item or not. More... | |
auto | get (const std::string &key) -> std::shared_ptr< XMLList > & |
Get element. More... | |
void | set (const std::string &key, const std::shared_ptr< XMLList > &val) |
Set element. More... | |
auto | pop (const std::string &key) -> std::shared_ptr< XMLList > |
Pop item. More... | |
Private Member Functions | |
XML (XML *, WeakString &) | |
Protected Constructor by string for child. More... | |
Private Attributes | |
std::string | tag |
Tag name. More... | |
std::string | value |
Value of the XML. More... | |
HashMap< std::string, std::string > | propertyMap |
Properties belongs to the XML. More... | |
XML is a class representing xml object.
The XML class provides methods and properties for working with XML objects.
The XML class (along with the XMLList and Namespace) implements the powerful XML-handling standard defined in ECMAScript for XML (E4X) specification.
XML class has a recursive, hierarchical relationship.
All XML objects're managed by shared_ptr.
Parsing comment is not supported yet.
It's not recommeded to creating an XML object which is not being managed by shared pointer.
Do not abuse values for expressing member variables.
Standard Usage | Non-standard usage abusing value |
---|---|
<memberList> <member id='jhnam88' name='Jeongho+Nam' birthdate='1988-03-11' /> <member id='master' name='Administartor' birthdate='2011-07-28' /> </memberList> | <member> <id>jhnam88</id> <name>Jeongho+Nam</name> <birthdate>1988-03-11</birthdate> </member> |
XML::XML | ( | ) |
Default Constructor.
Definition at line 36 of file XML.cpp.
Referenced by push_back(), and XML().
XML::XML | ( | const XML & | xml | ) |
Copy Constructor.
Not copying (shared) pointer of children xml objects, but copying the real objects of children xml
Definition at line 42 of file XML.cpp.
References propertyMap, tag, and value.
XML::XML | ( | XML && | xml | ) |
XML::XML | ( | WeakString | wStr | ) |
Constructor by string.
Parses a string so that constructs an XML object
str | A string representing xml object |
Definition at line 74 of file XML.cpp.
References samchon::WeakString::between(), samchon::WeakString::find(), samchon::HashMap< Key, T, Hash, Pred, Alloc >::pop(), samchon::WeakString::size(), samchon::WeakString::substr(), and samchon::WeakString::substring().
|
private |
Protected Constructor by string for child.
Parses a string so that creates an XML object It is called for creating children XML objects from parent XML object.
parent | Parent object who will contains this XML object |
str | A string to be parsed |
Definition at line 117 of file XML.cpp.
References samchon::WeakString::find(), propertyMap, push_back(), samchon::WeakString::rfind(), samchon::HashMap< Key, T, Hash, Pred, Alloc >::set(), samchon::WeakString::size(), samchon::WeakString::substr(), samchon::WeakString::substring(), tag, samchon::WeakString::trim(), value, and XML().
void XML::push_back | ( | const WeakString & | str | ) |
Add children xml objects by string representing them.
str | A string representing xml objects whould be belonged to this XML |
Definition at line 439 of file XML.cpp.
References samchon::WeakString::empty(), samchon::HashMap< std::string, std::shared_ptr< XMLList > >::has(), tag, and XML().
Referenced by XML().
void samchon::library::XML::push_back | ( | const std::shared_ptr< XML > | ) |
Add children xml.
xml | An xml object you want to add |
void XML::addAllProperty | ( | const std::shared_ptr< XML > | ) |
Add all properties from another XML.
xml | Target xml object to deliver its properties |
Definition at line 469 of file XML.cpp.
References propertyMap.
void XML::setTag | ( | const std::string & | tag | ) |
|
inline |
Set value of the XML.
_Ty | Type of the value |
val | The value to set |
Standard Usage | Non-standard usage abusing value |
---|---|
<memberList> <member id='jhnam88' name='Jeongho+Nam' birthdate='1988-03-11' /> <member id='master' name='Administartor' birthdate='2011-07-28' /> </memberList> | <member> <id>jhnam88</id> <name>Jeongho+Nam</name> <birthdate>1988-03-11</birthdate> </member> |
Definition at line 229 of file XML.hpp.
References samchon::WeakString::str().
|
inline |
Set a property with its key.
Definition at line 259 of file XML.hpp.
References samchon::HashMap< Key, T, Hash, Pred, Alloc >::set(), and samchon::WeakString::str().
void XML::eraseProperty | ( | const std::string & | tag | ) |
Erase a property by its key.
key | The key of the property to erase |
exception | Unable to find the element |
Definition at line 476 of file XML.cpp.
References propertyMap.
void XML::clearProperties | ( | ) |
auto XML::getTag | ( | ) | const -> std::string |
|
inline |
|
inline |
Get property.
Definition at line 326 of file XML.hpp.
References samchon::HashMap< Key, T, Hash, Pred, Alloc >::get().
auto XML::hasProperty | ( | const std::string & | tag | ) | const -> bool |
Test wheter a property exists or not.
Definition at line 491 of file XML.cpp.
References samchon::HashMap< Key, T, Hash, Pred, Alloc >::has(), propertyMap, samchon::WeakString::replaceAll(), tag, and samchon::WeakString::trim().
auto XML::getPropertyMap | ( | ) | const -> const HashMap<std::string, std::string>& |
auto XML::toString | ( | size_t | level = 0 | ) | const -> std::string |
|
private |
Tag name.
Definition at line 85 of file XML.hpp.
Referenced by getTag(), hasProperty(), push_back(), setTag(), toString(), and XML().
|
private |
Value of the XML.
Definition at line 94 of file XML.hpp.
Referenced by toString(), and XML().
|
private |
Properties belongs to the XML.
A Dictionary of properties accessing each property by its key.
Definition at line 106 of file XML.hpp.
Referenced by addAllProperty(), clearProperties(), eraseProperty(), getPropertyMap(), hasProperty(), toString(), and XML().