PROFASI  Version 1.5
Public Member Functions | List of all members
prf_xml::XML_Node Class Reference

A class to represent an XML node. More...

#include <prf_xml.hh>

Public Member Functions

 XML_Node ()
 Default constructor.
 XML_Node (const XML_Node &)
 Copy constructor.
void make_clone_of (const XML_Node *)
 Create a real detached copy with the same information.
 XML_Node (std::list< prf_xml::Chunk >::iterator bg, std::list< prf_xml::Chunk >::iterator nd)
 Construct from a range of "Chunks".
XML_Nodeoperator= (const XML_Node &)
 Assignment operator.
 XML_Node (std::string nm, std::string vl)
 Create a node with a tag name and some data.
void set_name (std::string nm)
 Set the tag name (no syntax check!!)
void set_value (std::string vl)
 Set the text data (no syntax check!!)
std::string name () const
 Retrieve the name of a node.
std::string value () const
 Retrieve the text data stored in the node.
bool is_leaf_node () const
 Whether the node is a leaf node.
std::string attribute (std::string a)
 Retrieve a particular attribute.
size_t n_attributes () const
 Number of attributes.
std::map< std::string,
std::string > & 
attributes ()
 Reference to the attribute map.
size_t n_children () const
 Number of children.
XML_Nodechild (size_t i)
 i'th child node
XML_Nodechild (std::string nm)
 Pointer to the first child node with a given name.
std::deque< XML_Node * > & children ()
 Reference to the deque of children.
int add_child_node (XML_Node *ch)
 Add a child node.
int remove_child_node (std::string nm)
 Remove a node from the deque of child nodes.
int remove_child_node (XML_Node *nd)
 Remove a child node.
int disown_child_node (XML_Node *nd)
 Disown a child node.
int add_child_node (std::string nm, std::string vl)
 Add a new child node with given name and value.
void clear_child_nodes ()
 Clear all child nodes.
state_type state () const
 Whether or not the XML node is in an error free state.
bool encloses (XML_Node &gn)
 Whether it encloses another XML node.
std::string make_string () const
 Make a string out of the information in the node and its children.
void write (prf::Output &op, int indent_level=0)
 Write the XML node and its children for visualisation.
int interpret_formatted_data ()
 Interpret formatted data as a series of child nodes.

Detailed Description

An XML node represents the information enclosed within the scope of an XML tag. It has a name, some data, and a deque of pointers to other nodes regarded as its children. These child nodes are the XML tags contained within the scope of the original tag. For example,

<group index="0" type="ACE">
<group index="1" type="LYS">
-0.3131207777043232   -1.3363358975000719   -3.1415926535897931
4.5758682133671185   2.8279753720956338   1.1606113829381837
3.1121544489086883   1.9936435953881690

represents a short tree with information about the beginning part of a peptide. The root node in this case has a name "protein". It has a few child nodes (i) A child node called "sequence", which contains the sequence of the peptide as its data and no children of its own. (ii) 2 child nodes with name "group". In this instance, these two are distinguishable by their attributes "index" and "type". Each group contains a child node of its own, called "dof", with the double precision values of, presumably, the degrees of freedom in that residue. Notice that the name of a node appears in the opening and closing tags that define the scope of the node. Tags for the child nodes are enclosed within the scope of the parent node. The opening tag can optionally contain one or more attributes of arbitray names. Attribute values must be enclosed in quotes. There are no commas between different attributes, so that they are only distinguished by identifying name="value" patterns.

This class is an interface to the attributes and information contained in an XML node and its children.

Constructor & Destructor Documentation

XML_Node::XML_Node ( std::list< prf_xml::Chunk >::iterator  bg,
std::list< prf_xml::Chunk >::iterator  nd 

Normally this should not concern you unless you intend to want to improve the construction of the XML tree in some way. It takes a range of Chunk objects and tries to generate a node out of it. The range of chunks is assumed to start with a begin tag, end with an end tag and contain only data within these tags, i.e., no enclosed child nodes. Read the documentation of the Chunk and XML_Mini classes for further details of how and why it is used. If you only want to use the XML module, you can safely ignore this function.

See Also
XML_Node::XML_Node ( std::string  nm,
std::string  vl 
nmName or tag name for the XML node
vlText data for the node

Member Function Documentation

std::string prf_xml::XML_Node::attribute ( std::string  a)

Empty string if the desired attribute does not exist

int XML_Node::disown_child_node ( XML_Node nd)

If nd is a child node, it will be removed from the child list but its contents will not be touched. So, the responsibility of deleting that node will no longer be with the original parent node.

int XML_Node::interpret_formatted_data ( )

This function interprets formatted data, and hence implements the XML template handling for ProFASi.

See Also
bool prf_xml::XML_Node::is_leaf_node ( ) const

Returns true, if the node has no children, no attributes, and the value text does not contain more than 80 characters.

void XML_Node::make_clone_of ( const XML_Node tg)

The copy constructor copies all elements, including the pointers. The child nodes are pointers to other XML_Nodes. So, if we construct a copy using the copy constructor, we end up with two XML_Nodes which have elements pointing to the same memory address. This could lead to problems when the nodes are deleted. When we want a duplicate, one should use this function instead.

std::string prf_xml::XML_Node::value ( ) const

If data is stored in the file non-contiguously with child XML tags interspersed between text data blocks, the data belonging to the node (and not to the child nodes) will be collected in one place. This function then returns all the data belonging to the node.

void XML_Node::write ( prf::Output &  op,
int  indent_level = 0 

This function is only to see that the XML parsing has worked. It writes the node tag, defines its scope like the scope of a C function, shows the attributes like arguments to the function, uses indentation to represent the hierarchy.

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

PROFASI: Protein Folding and Aggregation Simulator, Version 1.5
© (2005-2016) Anders Irbäck and Sandipan Mohanty
Documentation generated on Mon Jul 18 2016 using Doxygen version 1.8.2