Samchon Framework for CPP  1.0.0
samchon::library::XML Class Reference

#include <XML.hpp>

Collaboration diagram for samchon::library::XML:

Public Member Functions

 XML ()
 Default Constructor. More...
 
 XML (const XML &xml)
 Copy Constructor. More...
 
 XML (XML &&xml)
 Move Constructor. More...
 
 XML (WeakString wstr)
 
auto getTag () const -> std::string
 Get tag. More...
 
auto hasProperty (const std::string &key) const -> bool
 
auto getPropertyMap () const -> const HashMap< std::string, std::string > &
 
template<class T = std::string>
auto getValue () const -> T
 Get value. More...
 
template<class T = std::string>
auto getProperty (const std::string &key) const -> T
 Get property. More...
 
auto findProperty (const std::string &key) -> HashMap< std::string, std::string >::iterator
 
void setTag (const std::string &val)
 
template<typename T >
void setValue (const T &val)
 
template<typename T >
void setProperty (const std::string &key, const T &val)
 
void push_back (WeakString wstr)
 Add children xml objects by string representing them. More...
 
void push_back (const std::shared_ptr< XML > xml)
 Add children xml. More...
 
void insertAllProperties (const std::shared_ptr< XML > xml)
 
void eraseProperty (const std::string &key)
 
void clearProperties ()
 
auto toString (size_t level=0) const -> std::string
 
- Public Member Functions inherited from samchon::HashMap< std::string, std::shared_ptr< XMLList > >
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...
 

Detailed Description

A tree-structured XML object.

The class contains methods and properties for working with XML objects. The XML class (along with the XMLList) implements the powerful XML-handling standards defined in ECMAScript for XML (E4X) specification (ECMA-357 edition 2).

An XML object, it is composed with three members; tag, properties and value. As you know, XML is a tree structured data expression method. The tree-stucture; XML class realizes it by extending std.HashMap<string, XMLList>. Child XML objects are contained in the matched XMLList object being grouped by their tag name. The XMLList objects, they're stored in the std.HashMap (XML itself) with its key; common tag name of children XML objects.

1 class XML extends std.HashMap<string, XMLList>
2 {
3  private tag_: string;
4  private properties_: std.HashMap<string, string>;
5  private value_: string;
6 }
1 <?xml version="1.0" ?>
2 <TAG property_name={property_value}>
3 
4  <CHILD_TAG property_name={property_value}>{value}</CHILD_TAG>
5  <CHILD_TAG property_name={property_value}>{value}</CHILD_TAG>
6  <CHILD_TAG property_name={property_value}>{value}</CHILD_TAG>
7 
8 
9  <ANOTHER_TAG />
10 </TAG>

Use the toString() method to return a string representation of the XML object regardless of whether the XML object has simple content or complex content.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html https://github.com/samchon/framework/wiki/CPP-Library-XML

Author
Jeongho Nam http://samchon.org

Definition at line 69 of file XML.hpp.

Constructor & Destructor Documentation

samchon::library::XML::XML ( )
inline

Default Constructor.

Warning
Declare XML to managed by shared pointer

Definition at line 93 of file XML.hpp.

Referenced by push_back(), and XML().

Here is the caller graph for this function:

samchon::library::XML::XML ( const XML xml)
inline

Copy Constructor.

Not copying (shared) pointer of children xml objects, but copying the real objects of children xml

Definition at line 104 of file XML.hpp.

samchon::library::XML::XML ( XML &&  xml)
inline

Move Constructor.

Definition at line 129 of file XML.hpp.

samchon::library::XML::XML ( WeakString  wstr)
inline

Construct from string.

Creates XML object by parsing a string who represents xml structure.

Parameters
strA string represents XML structure.

Definition at line 144 of file XML.hpp.

References samchon::WeakString::between(), samchon::WeakString::find(), push_back(), samchon::WeakString::rfind(), samchon::HashMap< Key, T, Hash, Pred, Alloc >::set(), samchon::WeakString::size(), samchon::WeakString::substr(), samchon::WeakString::substring(), and XML().

Here is the call graph for this function:

Member Function Documentation

auto samchon::library::XML::getTag ( ) const -> std::string
inline

Get tag.

1 <TAG property_key={property_value}>{value}</TAG>
Returns
tag.

Definition at line 447 of file XML.hpp.

auto samchon::library::XML::hasProperty ( const std::string &  key) const -> bool
inline

Test whether a property exists.

1 <tag PROPERTY_KEY={property_value}>{value}</tag>
Returns
Whether a property has the key exists or not.

Definition at line 461 of file XML.hpp.

References samchon::HashMap< Key, T, Hash, Pred, Alloc >::has().

Referenced by findProperty().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::library::XML::getPropertyMap ( ) const -> const HashMap<std::string, std::string>&
inline

Get property map.

1 <tag PROPERTY_KEY1={PROPERTY_VALUE1}
2  PROPERTY_KEY2={PROPERTY_VALUE2}
3  PROPERTY_KEY3={PROPERTY_VALUE3}>{value}</tag>
Returns
HashMap containing properties' keys and values.

Definition at line 477 of file XML.hpp.

template<class T = std::string>
auto samchon::library::XML::getValue ( ) const -> T
inline

Get value.

1 <tag property_key={property_value}>{VALUE}</tag>
Returns
value.

Definition at line 495 of file XML.hpp.

template<class T = std::string>
auto samchon::library::XML::getProperty ( const std::string &  key) const -> T
inline

Get property.

Get property by its key, property name. If the matched key does not exist, then exception std.OutOfRange is thrown. Thus, it would better to test whether the key exits or not by calling the hasProperty() method before calling this getProperty().

This method can be substituted by getPropertyMap() such below:

1 <tag PROPERTY_KEY={PROPERTY_VALUE}>{value}</tag>
Returns
Value of the matched property.

Definition at line 537 of file XML.hpp.

References samchon::HashMap< Key, T, Hash, Pred, Alloc >::get().

Here is the call graph for this function:

auto samchon::library::XML::findProperty ( const std::string &  key) -> HashMap<std::string, std::string>::iterator
inline

Get iterator to property element.

Searches the properties for an element with a identifier equivalent to key and returns an iterator to it if found, otherwise it returns an iterator to end().

Two keys are considered equivalent if the properties' comparison object returns false reflexively (i.e., no matter the order in which the elements are passed as arguments).

Another member function, hasProperty() can be used to just check whether a particular key exists.

1 <tag PROPERTY_KEY={property_value}>{value}</tag>
Parameters
keyKey to be searched for
Returns
An iterator to the element, if an element with specified key is found, or HashMap.end() otherwise.

Definition at line 580 of file XML.hpp.

References hasProperty().

Here is the call graph for this function:

void samchon::library::XML::setTag ( const std::string &  val)
inline

Set tag.

Set tag name, identifier of this XML object.

If this XML object is belonged to, a child of, an XMLList and its related XML objects, then calling this setTag() method direclty is not recommended. Erase this XML object from parent objects and insert this object again.

1 <TAG property_key={property_value}>{value}</TAG>
Parameters
valTo be new tag.

Definition at line 617 of file XML.hpp.

template<typename T >
void samchon::library::XML::setValue ( const T &  val)
inline

Set value.

1 <tag property_key={property_value}>{VALUE}</tag>
Parameters
valTo be new value.

Definition at line 635 of file XML.hpp.

References samchon::WeakString::str().

Here is the call graph for this function:

template<typename T >
void samchon::library::XML::setProperty ( const std::string &  key,
const T &  val 
)
inline

Set property.

Set a property value with its key. If the key already exists, then the value will be overwritten to the property. Otherwise the key is not exist yet, then insert the key and value pair to property map.

This method can be substituted by getPropertyMap() such below:

1 <tag PROPERTY_KEY={PROPERTY_VALUE}>{value}</tag>
Parameters
keyKey, identifier of property to be newly inserted.
valueValue of new property to be newly inserted.

Definition at line 682 of file XML.hpp.

References samchon::HashMap< Key, T, Hash, Pred, Alloc >::set(), and samchon::WeakString::str().

Here is the call graph for this function:

void samchon::library::XML::push_back ( WeakString  wstr)
inline

Add children xml objects by string representing them.

Parameters
strA string representing xml objects whould be belonged to this XML

Definition at line 713 of file XML.hpp.

References samchon::WeakString::empty(), and XML().

Referenced by push_back(), and XML().

Here is the call graph for this function:

Here is the caller graph for this function:

void samchon::library::XML::push_back ( const std::shared_ptr< XML xml)
inline

Add children xml.

Parameters
xmlAn xml object you want to add

Definition at line 737 of file XML.hpp.

References samchon::HashMap< std::string, std::shared_ptr< XMLList > >::has(), push_back(), and XML().

Here is the call graph for this function:

void samchon::library::XML::insertAllProperties ( const std::shared_ptr< XML xml)
inline

Add all properties from other XML object.

All the properties in the obj are copied to this XML object. If this XML object has same property key in the obj, then value of the property will be replaced to obj's own. If you don't want to overwrite properties with same key, then use getPropertyMap() method.

1 let x: library.XML;
2 let y: library.XML;
3 
4 x.addAllProperties(y); // duplicated key exists, then overwrites
5 x.getPropertyMap().insert(y.getPropertyMap().begin(), y.getPropertyMap().end());
6  // ducpliated key, then ignores. only non-duplicateds are copied.
1 <tag PROPERTY_KEY1={property_value1}
2  PROPERTY_KEY2={property_value2}
3  PROPERTY_KEY3={property_value3}>{value}</tag>
Parameters
objTarget XML object to copy properties.

Definition at line 781 of file XML.hpp.

void samchon::library::XML::eraseProperty ( const std::string &  key)
inline

Erase property.

Erases a property by its key, property name. If the matched key does not exist, then exception std.OutOfRange is thrown. Thus, it would better to test whether the key exits or not by calling the hasProperty() method before calling this eraseProperty().

This method can be substituted by getPropertyMap().erase(key)``.

1 <tag PROPERTY_KEY={property_value}>{value}</tag>
Parameters
keyKey of the property to erase
Exceptions
{

Definition at line 803 of file XML.hpp.

void samchon::library::XML::clearProperties ( )
inline

Clear properties.

Remove all properties. It's same with calling getPropertyMap().clear().

1 <tag PROPERTY_KEY1={property_value1}
2  PROPERTY_KEY2={property_value2}
3  PROPERTY_KEY3={property_value3}>{value}</tag>

Definition at line 819 of file XML.hpp.

References samchon::WeakString::replaceAll().

Here is the call graph for this function:

auto samchon::library::XML::toString ( size_t  level = 0) const -> std::string
inline

XML object to xml string.

Returns a string representation of the XML object.

Parameters
tabNumber of tabs to spacing.
Returns
The string representation of the XML object.

Definition at line 908 of file XML.hpp.


The documentation for this class was generated from the following file: