Parent

LibXML::XML::Node

Public Instance Methods

attribute?() click to toggle source

Specifies if this is an attribute node

     # File lib/libxml/node.rb, line 207
207:       def attribute?
208:         node_type == ATTRIBUTE_NODE
209:       end
attribute_decl?() click to toggle source

Specifies if this is an attribute declaration node

     # File lib/libxml/node.rb, line 212
212:       def attribute_decl?
213:         node_type == ATTRIBUTE_DECL
214:       end
attributes?() click to toggle source

Determines whether this node has attributes

    # File lib/libxml/node.rb, line 9
 9:       def attributes?
10:         attributes.length > 0
11:       end
cdata?() click to toggle source

Specifies if this is an CDATA node

     # File lib/libxml/node.rb, line 217
217:       def cdata?
218:         node_type == CDATA_SECTION_NODE
219:       end
child?() click to toggle source
Alias for: first?
children() click to toggle source

Returns this node’s children as an array.

     # File lib/libxml/node.rb, line 131
131:       def children
132:         entries
133:       end
children?() click to toggle source
Alias for: first?
clone() click to toggle source

Create a shallow copy of the node. To create a deep copy call Node#copy(true)

    # File lib/libxml/node.rb, line 15
15:       def clone
16:         copy(false)
17:       end
comment?() click to toggle source

Specifies if this is an comment node

     # File lib/libxml/node.rb, line 222
222:       def comment?
223:         node_type == COMMENT_NODE
224:       end
context(namespaces=nil) → XPath::Context click to toggle source

Returns a new XML::XPathContext for the current node.

Namespaces is an optional array of XML::NS objects

    # File lib/libxml/node.rb, line 53
53:       def context(nslist = nil)
54:         if not self.doc
55:           raise(TypeError, "A node must belong to a document before a xpath context can be created")
56:         end
57: 
58:         context = XPath::Context.new(self.doc)
59:         context.node = self
60:         context.register_namespaces_from_node(self)
61:         context.register_namespaces_from_node(self.doc.root)
62:         context.register_namespaces(nslist) if nslist
63:         context
64:       end
docbook_doc?() click to toggle source

Specifies if this is an docbook node

     # File lib/libxml/node.rb, line 227
227:       def docbook_doc?
228:         node_type == DOCB_DOCUMENT_NODE
229:       end
doctype?() click to toggle source

Specifies if this is an doctype node

     # File lib/libxml/node.rb, line 232
232:       def doctype?
233:         node_type == DOCUMENT_TYPE_NODE
234:       end
document?() click to toggle source

Specifies if this is an document node

     # File lib/libxml/node.rb, line 237
237:       def document?
238:         node_type == DOCUMENT_NODE
239:       end
dtd?() click to toggle source

Specifies if this is an DTD node

     # File lib/libxml/node.rb, line 242
242:       def dtd?
243:         node_type == DTD_NODE
244:       end
dup → XML::Node click to toggle source

Create a shallow copy of the node. To create a deep copy call Node#copy(true)

    # File lib/libxml/node.rb, line 43
43:       def dup
44:         copy(false)
45:       end
each_attr() click to toggle source

——- Traversal —————- Iterates over this node’s attributes.

 doc = XML::Document.new('model/books.xml')
 doc.root.each_attr {|attr| puts attr}
     # File lib/libxml/node.rb, line 103
103:       def each_attr
104:         attributes.each do |attr|
105:           yield(attr)
106:         end
107:       end
each_element() click to toggle source

Iterates over this node’s child elements (nodes that have a node_type == ELEMENT_NODE).

 doc = XML::Document.new('model/books.xml')
 doc.root.each_element {|element| puts element}
     # File lib/libxml/node.rb, line 114
114:       def each_element
115:         each do |node|
116:           yield(node) if node.node_type == ELEMENT_NODE
117:         end
118:       end
element?() click to toggle source

Specifies if this is an element node

     # File lib/libxml/node.rb, line 247
247:       def element?
248:         node_type == ELEMENT_NODE
249:       end
element_decl?() click to toggle source

Specifies if this is an element declaration node

     # File lib/libxml/node.rb, line 257
257:       def element_decl?
258:         node_type == ELEMENT_DECL
259:       end
entity?() click to toggle source

Specifies if this is an entity node

     # File lib/libxml/node.rb, line 252
252:       def entity?
253:         node_type == ENTITY_NODE
254:       end
entity_ref?() click to toggle source

Specifies if this is an entity reference node

     # File lib/libxml/node.rb, line 262
262:       def entity_ref?
263:         node_type == ENTITY_REF_NODE
264:       end
find(namespaces=nil) → XPath::XPathObject click to toggle source

Return nodes matching the specified xpath expression. For more information, please refer to the documentation for XML::Document#find.

Namespaces is an optional array of XML::NS objects

    # File lib/libxml/node.rb, line 74
74:       def find(xpath, nslist = nil)
75:         self.context(nslist).find(xpath)
76:       end
find_first(namespaces=nil) → XML::Node click to toggle source

Return the first node matching the specified xpath expression. For more information, please refer to the documentation for the # method.

    # File lib/libxml/node.rb, line 84
84:       def find_first(xpath, nslist = nil)
85:         find(xpath, nslist).first
86:       end
first?() click to toggle source

Determines whether this node has a first node

     # File lib/libxml/node.rb, line 126
126:       def first?
127:         not first.nil?
128:       end
Also aliased as: child?, children?
fragment?() click to toggle source

Specifies if this is a fragment node

     # File lib/libxml/node.rb, line 267
267:       def fragment?
268:         node_type == DOCUMENT_FRAG_NODE
269:       end
html_doc?() click to toggle source

Specifies if this is a html document node

     # File lib/libxml/node.rb, line 272
272:       def html_doc?
273:         node_type == HTML_DOCUMENT_NODE
274:       end
inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) → "string" click to toggle source

Converts a node’s children, to a string representation. To include the node, use XML::Node#to_s. For more information about the supported options, see XML::Node#to_s.

    # File lib/libxml/node.rb, line 26
26:       def inner_xml(options = Hash.new)
27:         io = nil
28:         self.each do |node|
29:           xml = node.to_s(options)
30:           # Create the string IO here since we now know the encoding

31:           io = create_string_io(xml) unless io
32:           io << xml
33:         end
34: 
35:         io ? io.string : nil
36:       end
last?() click to toggle source

Determines whether this node has a last node

     # File lib/libxml/node.rb, line 146
146:       def last?
147:         not last.nil?
148:       end
namespace?() click to toggle source

Specifies if this is a namespace node (not if it has a namepsace)

     # File lib/libxml/node.rb, line 278
278:       def namespace?
279:         node_type == NAMESPACE_DECL
280:       end
namespacess → XML::Namespaces click to toggle source

Returns this node’s XML::Namespaces object, which is used to access the namespaces associated with this node.

    # File lib/libxml/node.rb, line 94
94:       def namespaces
95:         @namespaces ||= XML::Namespaces.new(self)
96:       end
next?() click to toggle source

Determines whether this node has a next node

     # File lib/libxml/node.rb, line 136
136:       def next?
137:         not self.next.nil?
138:       end
node_type_name() click to toggle source

Returns this node’s type name

     # File lib/libxml/node.rb, line 154
154:       def node_type_name
155:         case node_type
156:           # Most common choices first

157:           when ATTRIBUTE_NODE
158:             'attribute'
159:           when DOCUMENT_NODE
160:             'document_xml'
161:           when ELEMENT_NODE
162:             'element'
163:           when TEXT_NODE
164:             'text'
165:           
166:           # Now the rest  

167:           when ATTRIBUTE_DECL
168:             'attribute_decl'
169:           when CDATA_SECTION_NODE
170:             'cdata'
171:           when COMMENT_NODE
172:             'comment'
173:           when DOCB_DOCUMENT_NODE
174:             'document_docbook'
175:           when DOCUMENT_FRAG_NODE
176:             'fragment'
177:           when DOCUMENT_TYPE_NODE
178:             'doctype'
179:           when DTD_NODE
180:             'dtd'
181:           when ELEMENT_DECL
182:             'elem_decl'
183:           when ENTITY_DECL
184:             'entity_decl'
185:           when ENTITY_NODE
186:             'entity'
187:           when ENTITY_REF_NODE
188:             'entity_ref'
189:           when HTML_DOCUMENT_NODE
190:             'document_html'
191:           when NAMESPACE_DECL
192:             'namespace'
193:           when NOTATION_NODE
194:             'notation'
195:           when PI_NODE
196:             'pi'
197:           when XINCLUDE_START
198:             'xinclude_start'
199:           when XINCLUDE_END
200:             'xinclude_end'
201:           else
202:             raise(UnknownType, "Unknown node type: %n", node.node_type);
203:         end
204:       end
notation?() click to toggle source

Specifies if this is a notation node

     # File lib/libxml/node.rb, line 283
283:       def notation?
284:         node_type == NOTATION_NODE
285:       end
parent?() click to toggle source

Determines whether this node has a parent node

     # File lib/libxml/node.rb, line 121
121:       def parent?
122:         not parent.nil?
123:       end
pi?() click to toggle source

Specifies if this is a processiong instruction node

     # File lib/libxml/node.rb, line 288
288:       def pi?
289:         node_type == PI_NODE
290:       end
prev?() click to toggle source

Determines whether this node has a previous node

     # File lib/libxml/node.rb, line 141
141:       def prev?
142:         not prev.nil?
143:       end
properties() click to toggle source
    # File lib/libxml/properties.rb, line 11
11:       def properties
12:         warn('Node#properties is deprecated.  Use Node#attributes instead.')
13:         self.attributes
14:       end
properties?() click to toggle source
    # File lib/libxml/properties.rb, line 16
16:       def properties?
17:         warn('Node#properties? is deprecated.  Use Node#attributes? instead.')
18:         self.attributes?
19:       end
property(name) click to toggle source
   # File lib/libxml/properties.rb, line 6
6:       def property(name)
7:         warn('Node#properties is deprecated.  Use Node#[] instead.')
8:         self[name]
9:       end
text?() click to toggle source

Specifies if this is a text node

     # File lib/libxml/node.rb, line 293
293:       def text?
294:         node_type == TEXT_NODE
295:       end
xinclude_end?() click to toggle source

Specifies if this is an xinclude end node

     # File lib/libxml/node.rb, line 298
298:       def xinclude_end?
299:         node_type == XINCLUDE_END
300:       end
xinclude_start?() click to toggle source

Specifies if this is an xinclude start node

     # File lib/libxml/node.rb, line 303
303:       def xinclude_start?
304:         node_type == XINCLUDE_START
305:       end

Private Instance Methods

create_string_io(xml) click to toggle source
     # File lib/libxml/node.rb, line 390
390:       def create_string_io(xml)
391:         result = StringIO.new("")
392:         if defined?(::Encoding)
393:           result.set_encoding(xml.encoding)
394:         end
395:         result
396:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.