Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

dom_element.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 */
00028 
00031 
00032 #ifndef header_dom_element
00033 #define header_dom_element
00034 
00035 #if _MSC_VER > 1000
00036 #pragma once
00037 #endif
00038 
00039 #include "dom_node.h"
00040 
00041 //: DOM Element class.
00042 //- !group=Core/XML!
00043 //- !header=core.h!
00044 //- <p>By far the vast majority of objects (apart from text) that authors encounter when
00045 //- traversing a document are Element nodes. Assume the following XML document:</p>
00046 //- <pre>
00047 //- &lt;elementExample id="demo"&gt;
00048 //-  &lt;subelement1/&gt;
00049 //-  &lt;subelement2&gt;&lt;subsubelement/&gt;&lt;/subelement2&gt;
00050 //- &lt;/elementExample/gt;
00051 //- </pre>
00052 //- <p>When represented using DOM, the top node is an Element node for "elementExample",
00053 //- which contains two child Element nodes, one for "subelement1" and one for "subelement2".
00054 //- "subelement1" contains no child nodes.</p>
00055 //- <p>Elements may have attributes associated with them; since the Element interface
00056 //- inherits from Node, the generic Node interface method getAttributes may be used to
00057 //- retrieve the set of all attributes for an element. There are methods on the Element
00058 //- interface to retrieve either an Attr object by name or an attribute value by name.
00059 //- In XML, where an attribute value may contain entity references, an Attr object should
00060 //- be retrieved to examine the possibly fairly complex sub-tree representing the attribute
00061 //- value.</p>
00062 class CL_DomElement : public CL_DomNode
00063 {
00065 public:
00066         //: Constructs a DOM Element handle.
00067         CL_DomElement();
00068         
00069         CL_DomElement(CL_DomDocument &doc, const std::string &tag_name);
00070 
00071         CL_DomElement(const CL_SharedPtr<CL_DomNode_Generic> &impl);
00072 
00073         ~CL_DomElement();
00074 
00076 public:
00077         //: Returns the name of the element.
00078         std::string get_tag_name() const;
00079 
00081 public:
00082         //: Returns true if the element has the specified attribute.
00083         bool has_attribute(const std::string &name) const;
00084 
00085         //: Returns the specified attribute.
00086         std::string get_attribute(const std::string &name) const;
00087 
00088         //: Returns the specified attribute, using a default value if its not there.
00089         std::string get_attribute(const std::string &name, const std::string &default_value) const;
00090 
00091         //: Adds a new attribute.
00092         //- <p>If an attribute with that name is already present in the element, its value is
00093         //- changed to be that of the value parameter.</p>
00094         //- <p>This value is a simple string, it is not parsed as it is being set. So any markup
00095         //- (such as syntax to be recognized as an entity reference) is treated as literal text, and
00096         //- is appropriately escaped by the implementation when it is written out. In order to
00097         //- assign an attribute value that contains entity references, the user must create an Attr
00098         //- node plus any Text and EntityReference nodes, build the appropriate subtree, and use
00099         //- set_attribute_node to assign it as the value of an attribute.</p>
00100         void set_attribute(const std::string &name, const std::string &value);
00101 
00102         //: Removes an attribute by name.
00103         //- <p>If the removed attribute has a default value it is immediately replaced.</p>
00104         void remove_attribute(const std::string &name);
00105         
00106         //: Returns a NodeList of all descendant elements with a given tag name.
00107         //- <p>The descendant elements are returned in the order in which they would be
00108         //- encountered in a preorder traversal of the Element tree.</p>
00109         CL_DomNodeList get_elements_by_tag_name(const std::string &name);
00110 
00111         //: Merges any adjacent Text nodes.
00112         //- <p>Puts all Text nodes in the full depth of the sub-tree underneath this Element into
00113         //- a "normal" form where only markup (e.g., tags, comments, processing instructions, CDATA
00114         //- sections, and entity references) separates Text nodes, i.e., there are no adjacent Text
00115         //- nodes. This can be used to ensure that the DOM view of a document is the same as if it
00116         //- were saved and re-loaded, and is useful when operations (such as XPointer lookups) that
00117         //- depend on a particular document tree structure are to be used.</p>
00118         void normalize();
00119 
00120         //: Returns the text of all child Text nodes appended together.
00121         std::string get_text() const;
00122 };
00123 
00124 #endif

Generated on Sat Feb 19 22:51:15 2005 for npcore by  doxygen 1.4.1