wxXml2Node Class Reference

#include <xml2.h>

Inheritance diagram for wxXml2Node:

wxXml2BaseNode wxXml2Wrapper List of all members.

Detailed Description

Represents a node in XML documents.

Node has name and may have content and properties. Most common node types are wxXML2_TEXT_NODE (name and props are irrelevant) and wxXML2_ELEMENT_NODE (e.g. in <title>hi</title> there is element with name="title" and with irrelevant content and one child (of type=wxXML2_TEXT_NODE with content="hi").


Public Member Functions

 wxXml2Node ()
 Builds an empty node.
 wxXml2Node (wxXml2Document &doc, const wxString &name=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace)
 Builds a new node as root element of the given document.
 wxXml2Node (wxXml2NodeType type, wxXml2Node &parent, const wxString &name, const wxString &content=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace)
 Builds a new node as child of the given node.
 wxXml2Node (wxXml2NodeType type, wxXml2Document &doc, const wxString &name=wxEmptyString, const wxString &content=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace)
 Builds a new node unlinked from the main tree.
 wxXml2Node (xmlNode *node)
 Wraps the given XML node.
 wxXml2Node (const wxXml2Node &n)
 Copies the given wrapper (does not imply the XML structure copy).
 wxXml2Node (const wxXml2BaseNode &n)
 Copies the given wrapper (does not imply the XML structure copy).
virtual ~wxXml2Node ()
bool operator== (const wxXml2Node &node) const
bool operator!= (const wxXml2Node &p) const
wxXml2Nodeoperator= (const wxXml2Node &n)
wxXml2Node GetParent () const
wxXml2Node GetChildren () const
wxXml2Node GetFirstChild () const
wxXml2Node GetNext () const
wxXml2Node GetPrevious () const
wxXml2Document GetDoc () const
wxXml2Property GetProperties () const
wxXml2Namespace GetNamespace () const
wxXml2Namespace GetNamespaceDecl () const
wxString GetName () const
 Returns the name of this node.
wxString GetContent () const
 Returns the content of this node.
wxString GetNodeContent () const
 Returns the content of this node; this can be either the text carried directly by this node if it's a TEXT node or the aggregate string of the values carried by this node child's (TEXT and ENTITY_REF).
xmlNode * GetObj () const
 Returns the libxml2 node structure wrapped by this object.
bool GetPropVal (const wxString &propName, wxString *value) const
 Returns TRUE if a property named 'propName' exists in this node and, in this case, returns its value in 'value'.
wxString GetPropVal (const wxString &propName, const wxString &defaultVal) const
 Returns the value of the property named 'propName' if it exists, otherwise returns 'defaultVal'.
wxXml2Node Get (const wxString &name, int n=0) const
 Returns the n-th child named 'name', or wxXml2EmptyNode if it doesn't exist.
void SetName (const wxString &name)
 Sets the name of this node.
void SetContent (const wxString &cont)
 Sets the content of this node.
void SetProperties (const wxXml2Property &prop)
void SetNamespace (wxXml2Namespace &ns)
User-friendly creation.
These functions are safe & powerful. Use these when possible.

void CreateRoot (wxXml2Document &doc, const wxString &name=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace, wxXml2Property &props=wxXml2EmptyProperty)
 Creates this node as the ROOT of the given document.
void CreateChild (wxXml2NodeType type, wxXml2Node &parent, const wxString &name, const wxString &content=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace, wxXml2Property &props=wxXml2EmptyProperty, wxXml2Node &next=wxXml2EmptyNode)
 Creates a node which is attached to the given parent as one of its children.
void CreateTemp (wxXml2NodeType type, wxXml2Document &doc, const wxString &name=wxEmptyString, const wxString &content=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace, wxXml2Property &props=wxXml2EmptyProperty)
 Creates a temporary node unlinked from any XML tree (the wxXml2Document is required but it is not modified) which can be used to temporary store some data.
wxXml2Node AddContainerChild (const wxString &name)
 Creates a child which can contain other children.
wxXml2Node AddTextChild (const wxString &name, const wxString &content)
 Creates a container child (named 'name'), which contains a text child which contains the string 'content'.
wxXml2Node AddCommentChild (const wxString &content)
 Creates a comment node: .
wxXml2Node AddCDATAChild (const wxString &content)
 Creates a CDATA node: <![CDATA[content]]>.
wxXml2Node AddPIChild (const wxString &name, const wxString &content)
 Creates a PI node: <?name content ?>.
wxXml2Node AddBreakLineChild (int breaklines=1)
 Creates a text node which contains one (or more) break line characters.
wxXml2Property AddProperty (const wxString &name, const wxString &value)
 Creates a new wxXml2Property with the given name & value (NAME="value") and attaches it to the properties of this node.
wxXml2Namespace AddNamespace (const wxString &prefix, const wxString &href)
 Creates a new wxXml2Namespace with the given prefic & href and sets it as the namespace of this node.
Raw-creation functions
These functions should append the given objects at the end of the libxml2 node's list. Avoid them when possible.

void AddProperty (wxXml2Property &prop)
 Links a new property to this node.
void AddChild (wxXml2Node &node)
 Links a new child to this node.
void AddPrevious (wxXml2Node &node)
 Links the given node as previous node.
void AddNext (wxXml2Node &node)
 Links the given node as next node.
Miscellaneous
Some miscellaneous functions which work on wxXml2Nodes.

bool Contains (const wxXml2Node &tofind) const
 Returns TRUE if this node contains the given one.
bool HasProp (const wxString &propName) const
 Returns TRUE if this node has a property with the given name.
void MakeUpper ()
 Makes the name of this tag all uppercase.
void MakeLower ()
 Makes the name of this tag all lowercase.
bool Cmp (const wxXml2Node &node) const
 Returns TRUE if the given node is identic to this one.
bool CmpNoNs (const wxXml2Node &node) const
 Like Cmp() but this function checks only content, name and type.
wxXml2Node Replace (const wxXml2Node &newnode)
 Unlinks the old node from it's current context, prune the new one at the same place.
wxXml2Node Find (const wxString &name, const wxString &content=wxEmptyString, int occ=0, bool bNS=TRUE, bool recurse=TRUE) const
 Searches the occ-th occurence of a node with the given name & content, among the children of this node.
wxXml2Node Find (const wxXml2Node &tofind, int occ=0, bool bNS=TRUE, bool recurse=TRUE) const
 Searches the occ-th occurrence of a node like the given one among all the children of this object.
wxXml2Node Encapsulate (const wxString &nodename, const wxString &content=wxEmptyString, wxXml2Namespace &ns=wxXml2EmptyNamespace, wxXml2Property &props=wxXml2EmptyProperty)
 Encapsulates this node in another node with the given name; if the.

Protected Member Functions

void Build (const wxXml2NodeType type, wxXml2Node &parent, wxXml2Document &document=wxXml2EmptyDoc, wxXml2Namespace &ns=wxXml2EmptyNamespace, const wxString &name=wxEmptyString, const wxString &content=wxEmptyString, wxXml2Property &props=wxXml2EmptyProperty, wxXml2Node &next=wxXml2EmptyNode, wxXml2Node &previous=wxXml2EmptyNode, wxXml2Node &children=wxXml2EmptyNode)
 Builds a new XML node settings ALL its possible attributes: the type (wxXml2NodeType), the parent, the children, the next & previous nodes (wxXml2Node), the properties (wxXml2Property), the parent document (wxXml2Document), the name & content (wxString).
void Destroy ()
 Uses functions specific to xmlNode.


Constructor & Destructor Documentation

wxXml2Node::wxXml2Node (  )  [inline]

Builds an empty node.

If you need an empty node in a "read-only" operation (comparison, for example), you can use the global instance wxXml2EmptyNode.

wxXml2Node::wxXml2Node ( wxXml2Document doc,
const wxString &  name = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace 
) [inline]

Builds a new node as root element of the given document.

The node is automatically set as wxXML2_ELEMENT_NODE and will replace any other root node eventually set in the given document (the old node is destroyed). The root element of a document should have parent, next, previous == NULL.

wxXml2Node::wxXml2Node ( wxXml2NodeType  type,
wxXml2Node parent,
const wxString &  name,
const wxString &  content = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace 
) [inline]

Builds a new node as child of the given node.

wxXml2Node::wxXml2Node ( wxXml2NodeType  type,
wxXml2Document doc,
const wxString &  name = wxEmptyString,
const wxString &  content = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace 
) [inline]

Builds a new node unlinked from the main tree.

This node must be considered temporary until it is linked to another node in the main tree.

wxXml2Node::wxXml2Node ( xmlNode *  node  )  [inline]

Wraps the given XML node.

This function doesn't copy the given structure, it just attach it to this object.

wxXml2Node::wxXml2Node ( const wxXml2Node n  )  [inline]

Copies the given wrapper (does not imply the XML structure copy).

wxXml2Node::wxXml2Node ( const wxXml2BaseNode n  )  [inline]

Copies the given wrapper (does not imply the XML structure copy).

virtual wxXml2Node::~wxXml2Node (  )  [inline, virtual]


Member Function Documentation

wxXml2Node wxXml2Node::AddBreakLineChild ( int  breaklines = 1  ) 

Creates a text node which contains one (or more) break line characters.

In XML all characters in the content of the document are significant including blanks and formatting line breaks, so if you want to add a break line you MUST create a text child with '
' as content. The problem is that, if you use this function even once, libxml2 will automatically turn off its format algorithm for this node and all its children...

wxXml2Node wxXml2Node::AddCDATAChild ( const wxString &  content  ) 

Creates a CDATA node: <![CDATA[content]]>.

void wxXml2Node::AddChild ( wxXml2Node node  ) 

Links a new child to this node.

wxXml2Node wxXml2Node::AddCommentChild ( const wxString &  content  ) 

Creates a comment node: .

wxXml2Node wxXml2Node::AddContainerChild ( const wxString &  name  ) 

Creates a child which can contain other children.

wxXml2Namespace wxXml2Node::AddNamespace ( const wxString &  prefix,
const wxString &  href 
)

Creates a new wxXml2Namespace with the given prefic & href and sets it as the namespace of this node.

void wxXml2Node::AddNext ( wxXml2Node node  ) 

Links the given node as next node.

wxXml2Node wxXml2Node::AddPIChild ( const wxString &  name,
const wxString &  content 
)

Creates a PI node: <?name content ?>.

void wxXml2Node::AddPrevious ( wxXml2Node node  ) 

Links the given node as previous node.

void wxXml2Node::AddProperty ( wxXml2Property prop  ) 

Links a new property to this node.

wxXml2Property wxXml2Node::AddProperty ( const wxString &  name,
const wxString &  value 
)

Creates a new wxXml2Property with the given name & value (NAME="value") and attaches it to the properties of this node.

wxXml2Node wxXml2Node::AddTextChild ( const wxString &  name,
const wxString &  content 
)

Creates a container child (named 'name'), which contains a text child which contains the string 'content'.

to avoid the creation of the container child and to create directly a text node, use wxEmptyString (or "") as name.

void wxXml2Node::Build ( const wxXml2NodeType  type,
wxXml2Node parent,
wxXml2Document document = wxXml2EmptyDoc,
wxXml2Namespace ns = wxXml2EmptyNamespace,
const wxString &  name = wxEmptyString,
const wxString &  content = wxEmptyString,
wxXml2Property props = wxXml2EmptyProperty,
wxXml2Node next = wxXml2EmptyNode,
wxXml2Node previous = wxXml2EmptyNode,
wxXml2Node children = wxXml2EmptyNode 
) [protected]

Builds a new XML node settings ALL its possible attributes: the type (wxXml2NodeType), the parent, the children, the next & previous nodes (wxXml2Node), the properties (wxXml2Property), the parent document (wxXml2Document), the name & content (wxString).

bool wxXml2Node::Cmp ( const wxXml2Node node  )  const

Returns TRUE if the given node is identic to this one.

Checks only content, name, namespace and type.

bool wxXml2Node::CmpNoNs ( const wxXml2Node node  )  const

Like Cmp() but this function checks only content, name and type.

bool wxXml2Node::Contains ( const wxXml2Node tofind  )  const [inline]

Returns TRUE if this node contains the given one.

Obviously the function performs a recursive check.

void wxXml2Node::CreateChild ( wxXml2NodeType  type,
wxXml2Node parent,
const wxString &  name,
const wxString &  content = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace,
wxXml2Property props = wxXml2EmptyProperty,
wxXml2Node next = wxXml2EmptyNode 
)

Creates a node which is attached to the given parent as one of its children.

void wxXml2Node::CreateRoot ( wxXml2Document doc,
const wxString &  name = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace,
wxXml2Property props = wxXml2EmptyProperty 
)

Creates this node as the ROOT of the given document.

The XML root of a document is the node containing all other nodes. It can be preceded only by some special nodes. Consider the following:












    //! 

It's valid since the ROOT is preceded only by wxXML2_PI_NODEs and a DTD declaration. If you see something like:




    //! 

Then it's wrong: the ROOT node must contain all other container nodes.

void wxXml2Node::CreateTemp ( wxXml2NodeType  type,
wxXml2Document doc,
const wxString &  name = wxEmptyString,
const wxString &  content = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace,
wxXml2Property props = wxXml2EmptyProperty 
)

Creates a temporary node unlinked from any XML tree (the wxXml2Document is required but it is not modified) which can be used to temporary store some data.

Anyway, such node will be destroyed if you don't link it to a wider XML tree.

void wxXml2Node::Destroy (  )  [inline, protected, virtual]

Uses functions specific to xmlNode.

Reimplemented from wxXml2BaseNode.

wxXml2Node wxXml2Node::Encapsulate ( const wxString &  nodename,
const wxString &  content = wxEmptyString,
wxXml2Namespace ns = wxXml2EmptyNamespace,
wxXml2Property props = wxXml2EmptyProperty 
)

Encapsulates this node in another node with the given name; if the.

mynode.Encapsulate("newtag");

is called, then, mynode is

before: <mynodetagname>[...]</mynodetagname> after: <newtag><mynodetagname>[...]</mynodetagname></newtag>

Returns:
The new node (that is, *this)

wxXml2Node wxXml2Node::Find ( const wxXml2Node tofind,
int  occ = 0,
bool  bNS = TRUE,
bool  recurse = TRUE 
) const

Searches the occ-th occurrence of a node like the given one among all the children of this object.

Also checks namespace if bNS == TRUE. The recurse parameter can be used to disable the recursive behaviour (which is the default) of this function. In fact, if recurse == FALSE only the children of this node will be tested and the function won't descend into the child nodes.

wxXml2Node wxXml2Node::Find ( const wxString &  name,
const wxString &  content = wxEmptyString,
int  occ = 0,
bool  bNS = TRUE,
bool  recurse = TRUE 
) const

Searches the occ-th occurence of a node with the given name & content, among the children of this node.

If bNS == TRUE, this function also checks the namespace, otherwise the namespace will be irrelevant:

<myns:mynode>[...]</myns:mynode> and <mynode>[...]</mynode>

will both match this query:

Find("mynode", wxEmptyString, 0, FALSE);

This function does not check neither properties, children (except for the first text child which is tested if content != wxEmptyString) nor siblings. The recurse parameter can be used to disable the recursive behaviour (which is the default) of this function. In fact, if recurse == FALSE only the children of this node will be tested and the function won't descend into the child nodes.

wxXml2Node wxXml2Node::Get ( const wxString &  name,
int  n = 0 
) const [inline]

Returns the n-th child named 'name', or wxXml2EmptyNode if it doesn't exist.

wxXml2Node wxXml2Node::GetChildren (  )  const [inline]

Reimplemented from wxXml2BaseNode.

wxString wxXml2Node::GetContent (  )  const [inline]

Returns the content of this node.

Note that for nodes of type wxXML2_ELEMENT_NODE, the content is meaningless; for element nodes use GetNodeContent; see wxXml2NodeType for more info.

wxXml2Document wxXml2Node::GetDoc (  )  const [inline]

wxXml2Node wxXml2Node::GetFirstChild (  )  const [inline]

Reimplemented from wxXml2BaseNode.

wxString wxXml2Node::GetName (  )  const [inline]

Returns the name of this node.

Note that for nodes of type wxXML2_TEXT_NODE, the name is meaningless; see wxXml2NodeType for more info.

wxXml2Namespace wxXml2Node::GetNamespace (  )  const [inline]

wxXml2Namespace wxXml2Node::GetNamespaceDecl (  )  const [inline]

wxXml2Node wxXml2Node::GetNext (  )  const [inline]

Reimplemented from wxXml2BaseNode.

wxString wxXml2Node::GetNodeContent (  )  const [inline]

Returns the content of this node; this can be either the text carried directly by this node if it's a TEXT node or the aggregate string of the values carried by this node child's (TEXT and ENTITY_REF).

Entity references are substituted. This is especially useful for wxXML2_ELEMENT_NODE nodes.

xmlNode* wxXml2Node::GetObj (  )  const [inline]

Returns the libxml2 node structure wrapped by this object.

Use this function only if you know what to do with the returned structure.

Reimplemented from wxXml2BaseNode.

wxXml2Node wxXml2Node::GetParent (  )  const [inline]

Reimplemented from wxXml2BaseNode.

wxXml2Node wxXml2Node::GetPrevious (  )  const [inline]

Reimplemented from wxXml2BaseNode.

wxXml2Property wxXml2Node::GetProperties (  )  const [inline]

wxString wxXml2Node::GetPropVal ( const wxString &  propName,
const wxString &  defaultVal 
) const

Returns the value of the property named 'propName' if it exists, otherwise returns 'defaultVal'.

bool wxXml2Node::GetPropVal ( const wxString &  propName,
wxString *  value 
) const

Returns TRUE if a property named 'propName' exists in this node and, in this case, returns its value in 'value'.

bool wxXml2Node::HasProp ( const wxString &  propName  )  const

Returns TRUE if this node has a property with the given name.

void wxXml2Node::MakeLower (  ) 

Makes the name of this tag all lowercase.

Recursively updates the names of all children tags.

void wxXml2Node::MakeUpper (  ) 

Makes the name of this tag all uppercase.

Recursively updates the names of all children tags.

bool wxXml2Node::operator!= ( const wxXml2Node p  )  const [inline]

wxXml2Node& wxXml2Node::operator= ( const wxXml2Node n  )  [inline]

bool wxXml2Node::operator== ( const wxXml2Node node  )  const

wxXml2Node wxXml2Node::Replace ( const wxXml2Node newnode  ) 

Unlinks the old node from it's current context, prune the new one at the same place.

If cur was already inserted in a document it is first unlinked from its existing context.

Returns:
The new node (that is, *this)

void wxXml2Node::SetContent ( const wxString &  cont  )  [inline]

Sets the content of this node.

void wxXml2Node::SetName ( const wxString &  name  )  [inline]

Sets the name of this node.

void wxXml2Node::SetNamespace ( wxXml2Namespace ns  ) 

void wxXml2Node::SetProperties ( const wxXml2Property prop  ) 


The documentation for this class was generated from the following files:
Generated on Thu Sep 28 14:58:02 2006 for wxXml2 by  doxygen 1.4.7