Arc::XMLNode Class Reference

Wrapper for LibXML library Tree interface. More...

#include <XMLNode.h>

Inheritance diagram for Arc::XMLNode:
Arc::Config Arc::IniConfig Arc::Profile Arc::SecHandlerConfig Arc::XMLSecNode ArcSec::SecHandlerConfig Arc::ARCPolicyHandlerConfig Arc::DNListHandlerConfig

Public Member Functions

 XMLNode (void)
 XMLNode (const XMLNode &node)
 XMLNode (const std::string &xml)
 XMLNode (const char *xml, int len=-1)
 XMLNode (long ptr_addr)
 XMLNode (const NS &ns, const char *name)
 ~XMLNode (void)
void New (XMLNode &node) const
void Exchange (XMLNode &node)
void Move (XMLNode &node)
void Swap (XMLNode &node)
 operator bool (void) const
bool operator! (void) const
bool operator== (const XMLNode &node)
bool operator!= (const XMLNode &node)
bool Same (const XMLNode &node)
bool operator== (bool val)
bool operator!= (bool val)
bool operator== (const std::string &str)
bool operator!= (const std::string &str)
bool operator== (const char *str)
bool operator!= (const char *str)
XMLNode Child (int n=0)
XMLNode operator[] (const char *name) const
XMLNode operator[] (const std::string &name) const
XMLNode operator[] (int n) const
void operator++ (void)
void operator-- (void)
int Size (void) const
XMLNode Get (const std::string &name) const
std::string Name (void) const
std::string Prefix (void) const
std::string FullName (void) const
std::string Namespace (void) const
void Name (const char *name)
void Name (const std::string &name)
void GetXML (std::string &out_xml_str, bool user_friendly=false) const
void GetXML (std::string &out_xml_str, const std::string &encoding, bool user_friendly=false) const
void GetDoc (std::string &out_xml_str, bool user_friendly=false) const
 operator std::string (void) const
XMLNodeoperator= (const char *content)
XMLNodeoperator= (const std::string &content)
void Set (const std::string &content)
XMLNodeoperator= (const XMLNode &node)
XMLNode Attribute (int n=0)
XMLNode Attribute (const char *name)
XMLNode Attribute (const std::string &name)
XMLNode NewAttribute (const char *name)
XMLNode NewAttribute (const std::string &name)
int AttributesSize (void) const
void Namespaces (const NS &namespaces, bool keep=false, int recursion=-1)
NS Namespaces (void)
std::string NamespacePrefix (const char *urn)
XMLNode NewChild (const char *name, int n=-1, bool global_order=false)
XMLNode NewChild (const std::string &name, int n=-1, bool global_order=false)
XMLNode NewChild (const char *name, const NS &namespaces, int n=-1, bool global_order=false)
XMLNode NewChild (const std::string &name, const NS &namespaces, int n=-1, bool global_order=false)
XMLNode NewChild (const XMLNode &node, int n=-1, bool global_order=false)
void Replace (const XMLNode &node)
void Destroy (void)
XMLNodeList Path (const std::string &path)
XMLNodeList XPathLookup (const std::string &xpathExpr, const NS &nsList)
XMLNode GetRoot (void)
XMLNode Parent (void)
bool SaveToFile (const std::string &file_name) const
bool SaveToStream (std::ostream &out) const
bool ReadFromFile (const std::string &file_name)
bool ReadFromStream (std::istream &in)
bool Validate (const std::string &schema_file, std::string &err_msg)

Protected Member Functions

 XMLNode (xmlNodePtr node)

Protected Attributes

bool is_owner_
bool is_temporary_

Friends

bool MatchXMLName (const XMLNode &node1, const XMLNode &node2)
bool MatchXMLName (const XMLNode &node, const char *name)
bool MatchXMLName (const XMLNode &node, const std::string &name)
bool MatchXMLNamespace (const XMLNode &node1, const XMLNode &node2)
bool MatchXMLNamespace (const XMLNode &node, const char *uri)
bool MatchXMLNamespace (const XMLNode &node, const std::string &uri)

Detailed Description

Wrapper for LibXML library Tree interface.

This class wraps XML Node, Document and Property/Attribute structures. Each instance serves as pointer to actual LibXML element and provides convenient (for chosen purpose) methods for manipulating it. This class has no special ties to LibXML library and may be easily rewritten for any XML parser which provides interface similar to LibXML Tree. It implements only small subset of XML capabilities, which is probably enough for performing most of useful actions. This class also filters out (usually) useless textual nodes which are often used to make XML documents human-readable.


Constructor & Destructor Documentation

Arc::XMLNode::XMLNode ( xmlNodePtr  node  )  [inline, protected]

Private constructor for inherited classes Creates instance and links to existing LibXML structure. Acquired structure is not owned by class instance. If there is need to completely pass control of LibXML document to then instance's is_owner_ variable has to be set to true.

Arc::XMLNode::XMLNode ( void   )  [inline]

Constructor of invalid node Created instance does not point to XML element. All methods are still allowed for such instance but produce no results.

Arc::XMLNode::XMLNode ( const XMLNode node  )  [inline]

Copies existing instance. Underlying XML element is NOT copied. Ownership is NOT inherited. Strictly speaking it shuld be no const here - but that conflicts with C++.

Arc::XMLNode::XMLNode ( const std::string &  xml  ) 

Creates XML document structure from textual representation of XML document. Created structure is pointed and owned by constructed instance

Arc::XMLNode::XMLNode ( const char *  xml,
int  len = -1 
)

Same as previous

Arc::XMLNode::XMLNode ( long  ptr_addr  ) 

Copy constructor. Used by language bindigs

Arc::XMLNode::XMLNode ( const NS ns,
const char *  name 
)

Creates empty XML document structure with specified namespaces. Created XML contains only root element named 'name'. Created structure is pointed and owned by constructed instance

Arc::XMLNode::~XMLNode ( void   ) 

Destructor Also destroys underlying XML document if owned by this instance


Member Function Documentation

XMLNode Arc::XMLNode::Attribute ( const std::string &  name  )  [inline]

Returns XMLNode instance representing first attribute of node with specified by name

References Attribute().

XMLNode Arc::XMLNode::Attribute ( const char *  name  ) 

Returns XMLNode instance representing first attribute of node with specified by name

XMLNode Arc::XMLNode::Attribute ( int  n = 0  ) 

Returns list of all attributes of node.

Returns XMLNode instance reresenting n-th attribute of node.

Referenced by Attribute().

int Arc::XMLNode::AttributesSize ( void   )  const

Returns number of attributes of node

XMLNode Arc::XMLNode::Child ( int  n = 0  ) 

Returns XMLNode instance representing n-th child of XML element. If such does not exist invalid XMLNode instance is returned

void Arc::XMLNode::Destroy ( void   ) 

Destroys underlying XML element. XML element is unlinked from XML tree and destroyed. After this operation XMLNode instance becomes invalid

void Arc::XMLNode::Exchange ( XMLNode node  ) 

Exchanges XML (sub)trees. Following conbinations are possible If either this or node are refering owned XML tree (top level node) then references are simply exchanged. This operation is fast. If both this and node are refering to XML (sub)tree of different documents then (sub)trees are exchahed between documments. If both this and node are refering to XML (sub)tree of same document then (sub)trees are moved inside document. The main reason for this method is to provide effective way to insert one XML document inside another. One should take into account that if any of exchanged nodes is top level it must be also owner of document. Otherwise method will fail. If both nodes are top level owners and/or invlaid nodes then this method is identical to Swap().

std::string Arc::XMLNode::FullName ( void   )  const [inline]

Returns prefix:name of XML node

References Name(), and Prefix().

XMLNode Arc::XMLNode::Get ( const std::string &  name  )  const [inline]

Same as operator[]

References operator[]().

void Arc::XMLNode::GetDoc ( std::string &  out_xml_str,
bool  user_friendly = false 
) const

Fills argument with whole XML document textual representation

XMLNode Arc::XMLNode::GetRoot ( void   ) 

Get the root node from any child node of the tree

void Arc::XMLNode::GetXML ( std::string &  out_xml_str,
const std::string &  encoding,
bool  user_friendly = false 
) const

Fills argument with this instance XML subtree textual representation if the XML subtree is corresponding to the encoding format specified in the argument, e.g. utf-8

void Arc::XMLNode::GetXML ( std::string &  out_xml_str,
bool  user_friendly = false 
) const

Fills argument with this instance XML subtree textual representation

void Arc::XMLNode::Move ( XMLNode node  ) 

Moves content of this XML (sub)tree to node This opeartion is similar to New except that XML (sub)tree to refered by this is destroyed. This method is more effective than combination of New() and Destroy() because internally it is optimized not to copy data if not needed. The main purpose of this is to effectively extract part of XML document.

void Arc::XMLNode::Name ( const std::string &  name  )  [inline]

Assigns new name to XML node

References Name().

void Arc::XMLNode::Name ( const char *  name  ) 

Assigns new name to XML node

std::string Arc::XMLNode::Name ( void   )  const

Returns name of XML node

Referenced by FullName(), and Name().

std::string Arc::XMLNode::Namespace ( void   )  const

Returns namespace URI of XML node

std::string Arc::XMLNode::NamespacePrefix ( const char *  urn  ) 

Returns prefix of specified namespace. Empty string if no such namespace.

NS Arc::XMLNode::Namespaces ( void   ) 

Returns namespaces known at this node

void Arc::XMLNode::Namespaces ( const NS namespaces,
bool  keep = false,
int  recursion = -1 
)

Assigns namespaces of XML document at point specified by this instance. If namespace already exists it gets new prefix. New namespaces are added. It is useful to apply this method to XML being processed in order to refer to it's elements by known prefix. If keep is set to false existing namespace definition residing at this instance and below are removed (default beavior). If recursion is set to positive number then depth of prefix replacement is limited by this number (0 limits it to this node only). For unlimted recursion use -1. If recursion is limited then value of keep is ignored and existing namespaces are always kept.

void Arc::XMLNode::New ( XMLNode node  )  const

Creates a copy of XML (sub)tree. If object does not represent whole document - top level document is created. 'node' becomes a pointer owning new XML document.

XMLNode Arc::XMLNode::NewAttribute ( const std::string &  name  )  [inline]

Creates new attribute with specified name.

References NewAttribute().

XMLNode Arc::XMLNode::NewAttribute ( const char *  name  ) 

Creates new attribute with specified name.

Referenced by NewAttribute().

XMLNode Arc::XMLNode::NewChild ( const XMLNode node,
int  n = -1,
bool  global_order = false 
)

Link a copy of supplied XML node as child. Returns instance refering to new child. XML element is a copy of supplied one but not owned by returned instance

XMLNode Arc::XMLNode::NewChild ( const std::string &  name,
const NS namespaces,
int  n = -1,
bool  global_order = false 
) [inline]
XMLNode Arc::XMLNode::NewChild ( const char *  name,
const NS namespaces,
int  n = -1,
bool  global_order = false 
)

Creates new child XML element at specified position with specified name and namespaces. For more information look at NewChild(const char*,int,bool)

XMLNode Arc::XMLNode::NewChild ( const std::string &  name,
int  n = -1,
bool  global_order = false 
) [inline]
XMLNode Arc::XMLNode::NewChild ( const char *  name,
int  n = -1,
bool  global_order = false 
)

Creates new child XML element at specified position with specified name. Default is to put it at end of list. If global order is true position applies to whole set of children, otherwise only to children of same name. Returns created node.

Referenced by NewChild().

Arc::XMLNode::operator bool ( void   )  const [inline]

Returns true if instance points to XML element - valid instance

References is_temporary_.

Arc::XMLNode::operator std::string ( void   )  const

Returns textual content of node excluding content of children nodes

bool Arc::XMLNode::operator! ( void   )  const [inline]

Returns true if instance does not point to XML element - invalid instance

References is_temporary_.

bool Arc::XMLNode::operator!= ( const char *  str  )  [inline]

This operator is needed to avoid ambiguity

bool Arc::XMLNode::operator!= ( const std::string &  str  )  [inline]

This operator is needed to avoid ambiguity

bool Arc::XMLNode::operator!= ( bool  val  )  [inline]

This operator is needed to avoid ambiguity

bool Arc::XMLNode::operator!= ( const XMLNode node  )  [inline]

Returns false if 'node' represents same XML element

void Arc::XMLNode::operator++ ( void   ) 

Convenience operator to switch to next element of same name. If there is no such node this object becomes invalid.

void Arc::XMLNode::operator-- ( void   ) 

Convenience operator to switch to previous element of same name. If there is no such node this object becomes invalid.

XMLNode& Arc::XMLNode::operator= ( const XMLNode node  ) 

Make instance refer to another XML node. Ownership is not inherited. Due to nature of XMLNode there should be no const here, but that does not fit into C++.

XMLNode& Arc::XMLNode::operator= ( const std::string &  content  )  [inline]

Sets textual content of node. All existing children nodes are discarded.

References operator=().

XMLNode& Arc::XMLNode::operator= ( const char *  content  ) 

Sets textual content of node. All existing children nodes are discarded.

Referenced by operator=(), and Set().

bool Arc::XMLNode::operator== ( const char *  str  )  [inline]

This operator is needed to avoid ambiguity

bool Arc::XMLNode::operator== ( const std::string &  str  )  [inline]

This operator is needed to avoid ambiguity

bool Arc::XMLNode::operator== ( bool  val  )  [inline]

This operator is needed to avoid ambiguity

bool Arc::XMLNode::operator== ( const XMLNode node  )  [inline]

Returns true if 'node' represents same XML element

Referenced by Same().

XMLNode Arc::XMLNode::operator[] ( int  n  )  const

Returns XMLNode instance representing n-th node in sequence of siblings of same name. It's main purpose is to be used to retrieve element in array of children of same name like node["name"][5]. This method should not be marked const because obtaining unrestricted XMLNode of child element allows modification of underlying XML tree. But in order to keep const in other places non-const-handling is passed to programmer. Otherwise C++ compiler goes nuts.

XMLNode Arc::XMLNode::operator[] ( const std::string &  name  )  const [inline]

Similar to previous method

References operator[]().

XMLNode Arc::XMLNode::operator[] ( const char *  name  )  const

Returns XMLNode instance representing first child element with specified name. Name may be "namespace_prefix:name", "namespace_uri:name" or simply "name". In last case namespace is ignored. If such node does not exist invalid XMLNode instance is returned. This method should not be marked const because obtaining unrestricted XMLNode of child element allows modification of underlying XML tree. But in order to keep const in other places non-const-handling is passed to programmer. Otherwise C++ compiler goes nuts.

Referenced by Get(), and operator[]().

XMLNode Arc::XMLNode::Parent ( void   ) 

Get the parent node from any child node of the tree

XMLNodeList Arc::XMLNode::Path ( const std::string &  path  ) 

Collects nodes corresponding to specified path. This is a convenience function to cover common use of XPath but without performance hit. Path is made of node_name[/node_name[...]] and is relative to current node. node_names are treated in same way as in operator[]. Returns all nodes which are represented by path.

std::string Arc::XMLNode::Prefix ( void   )  const

Returns namespace prefix of XML node

Referenced by FullName().

bool Arc::XMLNode::ReadFromFile ( const std::string &  file_name  ) 

Read XML document from file and associate it with this node

bool Arc::XMLNode::ReadFromStream ( std::istream &  in  ) 

Read XML document from stream and associate it with this node

void Arc::XMLNode::Replace ( const XMLNode node  ) 

Makes a copy of supplied XML node and makes this instance refere to it

bool Arc::XMLNode::Same ( const XMLNode node  )  [inline]

Returns true if 'node' represents same XML element - for bindings

References operator==().

bool Arc::XMLNode::SaveToFile ( const std::string &  file_name  )  const

Save string representation of node to file

bool Arc::XMLNode::SaveToStream ( std::ostream &  out  )  const

Save string representation of node to stream

void Arc::XMLNode::Set ( const std::string &  content  )  [inline]

Same as operator=. Used for bindings.

References operator=().

int Arc::XMLNode::Size ( void   )  const

Returns number of children nodes

void Arc::XMLNode::Swap ( XMLNode node  ) 

Swaps XML (sub)trees to this this and node refer. For XML subtrees this method is not anyhow different then using combinaiion XMLNode tmp=*this; *this=node; node=tmp; But in case of either this or node owning XML document ownership is swapped too. And this is a main purpose of Swap() method.

bool Arc::XMLNode::Validate ( const std::string &  schema_file,
std::string &  err_msg 
)

Remove all eye-candy information leaving only informational parts * void Purify(void); XML schema validation against the schema file defined as argument

XMLNodeList Arc::XMLNode::XPathLookup ( const std::string &  xpathExpr,
const NS nsList 
)

Uses xPath to look up the whole xml structure, Returns a list of XMLNode points. The xpathExpr should be like "//xx:child1/" which indicates the namespace and node that you would like to find; The nsList is the namespace the result should belong to (e.g. xx="uri:test"). Query is run on whole XML document but only the elements belonging to this XML subtree are returned.


Friends And Related Function Documentation

bool MatchXMLName ( const XMLNode node,
const std::string &  name 
) [friend]

Returns true if 'name' matches name of 'node'. If name contains prefix it's checked too

bool MatchXMLName ( const XMLNode node,
const char *  name 
) [friend]

Returns true if 'name' matches name of 'node'. If name contains prefix it's checked too

bool MatchXMLName ( const XMLNode node1,
const XMLNode node2 
) [friend]

Returns true if underlying XML elements have same names

bool MatchXMLNamespace ( const XMLNode node,
const std::string &  uri 
) [friend]

Returns true if 'namespace' matches 'node's namespace.

bool MatchXMLNamespace ( const XMLNode node,
const char *  uri 
) [friend]

Returns true if 'namespace' matches 'node's namespace.

bool MatchXMLNamespace ( const XMLNode node1,
const XMLNode node2 
) [friend]

Returns true if underlying XML elements belong to same namespaces


Field Documentation

bool Arc::XMLNode::is_owner_ [protected]

If true node is owned by this instance - hence released in destructor. Normally that may be true only for top level node of XML document.

bool Arc::XMLNode::is_temporary_ [protected]

This variable is for future

Referenced by operator bool(), and operator!().


The documentation for this class was generated from the following file:
Generated on Wed Jun 27 11:54:22 2012 for Hosting Environment (Daemon) by  doxygen 1.6.3