Class: Wx::XmlNode
- Inherits:
-
Object
- Object
- Wx::XmlNode
- Defined in:
- lib/wx/doc/gen/xml_node.rb
Overview
This class is untracked and should not be derived from nor instances extended!
Represents a node in an XML document.
See XmlDocument. Each node is named and depending on the node type it may also hold content or be given attributes. The two most common node types are Wx::XmlNodeType::XML_ELEMENT_NODE and Wx::XmlNodeType::XML_TEXT_NODE. Wx::XmlNodeType::XML_ELEMENT_NODE represents a pair of XML element tags, whilst Wx::XmlNodeType::XML_TEXT_NODE represents the text value that can belong to the element. A Wx::XmlNodeType::XML_ELEMENT_NODE has a title, and optionally attributes, but does not have any content. A Wx::XmlNodeType::XML_TEXT_NODE does not have a title or attributes but should normally have content. For example: in the XML fragment <title>hi</title>
there is an element node with the name title and a single text node child with the text hi as content. A Wx::XmlNodeType::XML_PI_NODE represents a Processing Instruction (PI) node with the name parameter set as the target and the contents parameter set as the instructions. Note that whilst the PI instructions are often in the form of pseudo-attributes, these do not use the node’s attribute member. It is the user’s responsibility to code and decode the PI instruction text. The Wx::XmlNodeType::XML_DOCUMENT_TYPE_NODE is not implemented at this time. Instead, you should get and set the DOCTYPE values using the XmlDocument class. If Setup::USE_UNICODE is 0, all strings are encoded in the encoding given to Wx::XmlDocument::Load (default is UTF-8).
Once a XmlNode has been added to a XmlDocument it becomes owned by the document and this has two implications. Firstly, the XmlDocument takes responsibility for deleting the node so the user should not delete it; and secondly, a XmlNode must always be created on the heap and never on the stack.
Category: XML
Instance Method Summary collapse
-
#add_attribute(name, value) ⇒ void
Appends an attribute with given name and value to the list of attributes for this node.
-
#add_child(child) ⇒ void
Adds node child as the last child of this node.
-
#delete_attribute(name) ⇒ Boolean
Removes the first attributes which has the given name from the list of attributes for this node.
-
#get_attribute(attrName, defaultVal = ('')) ⇒ String
(also: #attribute)
Returns the value of the attribute named attrName if it does exist.
-
#get_children ⇒ Wx::XmlNode
(also: #children)
Returns the first child of this node.
-
#get_content ⇒ Wx::String
(also: #content)
Returns the content of this node.
-
#get_depth(grandparent = nil) ⇒ Integer
(also: #depth)
Returns the number of nodes which separate this node from grandparent.
-
#get_line_number ⇒ Integer
(also: #line_number)
Returns line number of the node in the input XML file or
-1
if it is unknown. -
#get_name ⇒ Wx::String
(also: #name)
Returns the name of this node.
-
#get_next ⇒ Wx::XmlNode
(also: #next_)
Returns a pointer to the sibling of this node or NULL if there are no siblings.
-
#get_no_conversion ⇒ Boolean
(also: #no_conversion)
Returns a flag indicating whether encoding conversion is necessary when saving.
-
#get_node_content ⇒ String
(also: #node_content)
Returns the content of the first child node of type Wx::XmlNodeType::XML_TEXT_NODE or Wx::XmlNodeType::XML_CDATA_SECTION_NODE.
-
#get_parent ⇒ Wx::XmlNode
(also: #parent)
Returns a pointer to the parent of this node or NULL if this node has no parent.
-
#get_type ⇒ Wx::XmlNodeType
(also: #type)
Returns the type of this node.
-
#has_attribute(attrName) ⇒ Boolean
(also: #has_attribute?)
Returns true if this node has a attribute named attrName.
-
#initialize(*args) ⇒ XmlNode
constructor
A new instance of XmlNode.
-
#insert_child(child, followingNode) ⇒ Boolean
Inserts the child node immediately before followingNode in the children list.
-
#insert_child_after(child, precedingNode) ⇒ Boolean
Inserts the child node immediately after precedingNode in the children list.
-
#is_whitespace_only ⇒ Boolean
(also: #whitespace_only?)
Returns true if the content of this node is a string containing only whitespaces (spaces, tabs, new lines, etc).
-
#set_content(con) ⇒ void
(also: #content=)
Sets the content of this node.
-
#set_name(name) ⇒ void
(also: #name=)
Sets the name of this node.
-
#set_no_conversion(noconversion) ⇒ void
(also: #no_conversion=)
Sets a flag to indicate whether encoding conversion is necessary when saving.
-
#set_type(type) ⇒ void
(also: #type=)
Sets the type of this node.
Constructor Details
#initialize(type, name, content = (''), lineNo = -1) ⇒ Wx::XmlNode #initialize(node) ⇒ Wx::XmlNode
Returns a new instance of XmlNode.
131 |
# File 'lib/wx/doc/gen/xml_node.rb', line 131 def initialize(*args) end |
Instance Method Details
#add_attribute(name, value) ⇒ void
This method returns an undefined value.
Appends an attribute with given name and value to the list of attributes for this node.
137 |
# File 'lib/wx/doc/gen/xml_node.rb', line 137 def add_attribute(name, value) end |
#add_child(child) ⇒ void
This method returns an undefined value.
Adds node child as the last child of this node.
Once added, the XML tree takes ownership of this object and there is no need to delete it.
Note that this function works in O(n) time where n is the number of existing children. Consequently, adding large number of child nodes using this method can be expensive, because it has O(n^2) time complexity in number of nodes to be added. Use #insert_child_after to populate XML tree in linear time.
152 |
# File 'lib/wx/doc/gen/xml_node.rb', line 152 def add_child(child) end |
#delete_attribute(name) ⇒ Boolean
Removes the first attributes which has the given name from the list of attributes for this node.
157 |
# File 'lib/wx/doc/gen/xml_node.rb', line 157 def delete_attribute(name) end |
#get_attribute(attrName, defaultVal = ('')) ⇒ String Also known as: attribute
Returns the value of the attribute named attrName if it does exist.
If it does not exist, the defaultVal is returned.
165 |
# File 'lib/wx/doc/gen/xml_node.rb', line 165 def get_attribute(attrName, defaultVal=('')) end |
#get_children ⇒ Wx::XmlNode Also known as: children
Returns the first child of this node.
To get a pointer to the second child of this node (if it does exist), use the #get_next function on the returned value.
172 |
# File 'lib/wx/doc/gen/xml_node.rb', line 172 def get_children; end |
#get_content ⇒ Wx::String Also known as: content
Returns the content of this node.
Can be an empty string. Be aware that for nodes of type Wx::XmlNodeType::XML_ELEMENT_NODE (the most used node type) the content is an empty string. See #get_node_content for more details.
179 |
# File 'lib/wx/doc/gen/xml_node.rb', line 179 def get_content; end |
#get_depth(grandparent = nil) ⇒ Integer Also known as: depth
Returns the number of nodes which separate this node from grandparent.
This function searches only the parents of this node until it finds grandparent or the NULL node (which is the parent of non-linked nodes or the parent of a Wx::XmlDocument‘s root element node).
187 |
# File 'lib/wx/doc/gen/xml_node.rb', line 187 def get_depth(grandparent=nil) end |
#get_line_number ⇒ Integer Also known as: line_number
Returns line number of the node in the input XML file or -1
if it is unknown.
200 |
# File 'lib/wx/doc/gen/xml_node.rb', line 200 def get_line_number; end |
#get_name ⇒ Wx::String Also known as: name
Returns the name of this node.
Can be an empty string (e.g. for nodes of type Wx::XmlNodeType::XML_TEXT_NODE or Wx::XmlNodeType::XML_CDATA_SECTION_NODE).
207 |
# File 'lib/wx/doc/gen/xml_node.rb', line 207 def get_name; end |
#get_next ⇒ Wx::XmlNode Also known as: next_
Returns a pointer to the sibling of this node or NULL if there are no siblings.
212 |
# File 'lib/wx/doc/gen/xml_node.rb', line 212 def get_next; end |
#get_no_conversion ⇒ Boolean Also known as: no_conversion
Returns a flag indicating whether encoding conversion is necessary when saving.
The default is false. You can improve saving efficiency considerably by setting this value.
195 |
# File 'lib/wx/doc/gen/xml_node.rb', line 195 def get_no_conversion; end |
#get_node_content ⇒ String Also known as: node_content
Returns the content of the first child node of type Wx::XmlNodeType::XML_TEXT_NODE or Wx::XmlNodeType::XML_CDATA_SECTION_NODE.
This function is very useful since the XML snippet "<tagname>tagcontent</tagname>"
is represented by expat with the following tag tree:
wxXML_ELEMENT_NODE name="tagname", content=""
|-- wxXML_TEXT_NODE name="", content="tagcontent"
or eventually:
wxXML_ELEMENT_NODE name="tagname", content=""
|-- wxXML_CDATA_SECTION_NODE name="", content="tagcontent"
An empty string is returned if the node has no children of type Wx::XmlNodeType::XML_TEXT_NODE or Wx::XmlNodeType::XML_CDATA_SECTION_NODE, or if the content of the first child of such types is empty.
233 |
# File 'lib/wx/doc/gen/xml_node.rb', line 233 def get_node_content; end |
#get_parent ⇒ Wx::XmlNode Also known as: parent
Returns a pointer to the parent of this node or NULL if this node has no parent.
238 |
# File 'lib/wx/doc/gen/xml_node.rb', line 238 def get_parent; end |
#get_type ⇒ Wx::XmlNodeType Also known as: type
Returns the type of this node.
243 |
# File 'lib/wx/doc/gen/xml_node.rb', line 243 def get_type; end |
#has_attribute(attrName) ⇒ Boolean Also known as: has_attribute?
Returns true if this node has a attribute named attrName.
249 |
# File 'lib/wx/doc/gen/xml_node.rb', line 249 def has_attribute(attrName) end |
#insert_child(child, followingNode) ⇒ Boolean
Inserts the child node immediately before followingNode in the children list.
Once inserted, the XML tree takes ownership of the new child and there is no need to delete it. true if followingNode has been found and the child node has been inserted.
For historical reasons, followingNode may be NULL. In that case, then child is prepended to the list of children and becomes the first child of this node, i.e. it behaves identically to using the first children (as returned by #get_children) for followingNode).
267 |
# File 'lib/wx/doc/gen/xml_node.rb', line 267 def insert_child(child, followingNode) end |
#insert_child_after(child, precedingNode) ⇒ Boolean
Inserts the child node immediately after precedingNode in the children list.
Once inserted, the XML tree takes ownership of the new child and there is no need to delete it. true if precedingNode has been found and the child node has been inserted.
278 |
# File 'lib/wx/doc/gen/xml_node.rb', line 278 def insert_child_after(child, precedingNode) end |
#is_whitespace_only ⇒ Boolean Also known as: whitespace_only?
Returns true if the content of this node is a string containing only whitespaces (spaces, tabs, new lines, etc).
Note that this function is locale-independent since the parsing of XML documents must always produce the exact same tree regardless of the locale it runs under.
284 |
# File 'lib/wx/doc/gen/xml_node.rb', line 284 def is_whitespace_only; end |
#set_content(con) ⇒ void Also known as: content=
This method returns an undefined value.
Sets the content of this node.
290 |
# File 'lib/wx/doc/gen/xml_node.rb', line 290 def set_content(con) end |
#set_name(name) ⇒ void Also known as: name=
This method returns an undefined value.
Sets the name of this node.
296 |
# File 'lib/wx/doc/gen/xml_node.rb', line 296 def set_name(name) end |
#set_no_conversion(noconversion) ⇒ void Also known as: no_conversion=
This method returns an undefined value.
Sets a flag to indicate whether encoding conversion is necessary when saving.
The default is false. You can improve saving efficiency considerably by setting this value.
305 |
# File 'lib/wx/doc/gen/xml_node.rb', line 305 def set_no_conversion(noconversion) end |
#set_type(type) ⇒ void Also known as: type=
This method returns an undefined value.
Sets the type of this node.
311 |
# File 'lib/wx/doc/gen/xml_node.rb', line 311 def set_type(type) end |