Class: Ayril::XMLNode
- Inherits:
-
NSXMLNode
- Object
- NSXMLNode
- Ayril::XMLNode
show all
- Includes:
- NodeManipulation, NodeTraversal
- Defined in:
- lib/ayril/xml_node.rb,
lib/ayril/xml_node/node_traversal.rb,
lib/ayril/xml_node/node_manipulation.rb
Defined Under Namespace
Modules: NodeManipulation, NodeTraversal
Class Method Summary
collapse
Instance Method Summary
collapse
#adjacent, #ancestors, #at, #contains?, #descendant_of?, #descendants, #down, #empty?, #first_descendant, #immediate_descendants, #next, #next_element_sibling, #next_siblings, #previous, #previous_element_sibling, #previous_siblings, #recursively_collect, #select, #select_by_xpath, #siblings, #up
#clean_whitespace, #inner_html, #remove, #replace, #update
Class Method Details
.attributeWithName(name, URI: uri, stringValue: string) ⇒ Object
64
65
66
67
68
|
# File 'lib/ayril/xml_node.rb', line 64
def self.attributeWithName(name, stringValue: string)
e = XMLElement.alloc.initWithName "r"
e.setAttributesAsDictionary name => string
(e.attributeForName name).tap { |a| a.detach }
end
|
81
82
83
84
|
# File 'lib/ayril/xml_node.rb', line 81
def self.(string)
d = XMLDocument.alloc.initWithXMLString "<r><!--#{string}--></r>", options: 0, error: nil
d.rootElement.childAtIndex(0).tap { |n| n.detach }
end
|
XXX: Why raise NotImplementedError?
xmldocs with text nodes failed to parse and returned nil..?
def initWithKind(kind) raise NotImplementedError end def initWithKind(kind, options: options) raise NotImplementedError end
36
37
38
|
# File 'lib/ayril/xml_node.rb', line 36
def self.document
XMLDocument.alloc
end
|
.documentWithRootElement(element) ⇒ Object
40
41
42
|
# File 'lib/ayril/xml_node.rb', line 40
def self.documentWithRootElement(element)
XMLDocument.alloc.initWithRootElement element
end
|
.elementWithName(name, URI: uri) ⇒ Object
44
45
46
|
# File 'lib/ayril/xml_node.rb', line 44
def self.elementWithName(name)
XMLElement.alloc.initWithName name
end
|
.textWithStringValue(string) ⇒ Object
76
77
78
79
|
# File 'lib/ayril/xml_node.rb', line 76
def self.textWithStringValue(string)
d = XMLDocument.initWithXMLString "<r>#{string}</r>", options: 0, error: nil
d.rootElement.childAtIndex(0).tap { |n| n.detach }
end
|
Instance Method Details
#attr? ⇒ Boolean
Also known as:
attribute?
108
|
# File 'lib/ayril/xml_node.rb', line 108
def attr?; self.kind == NSXMLAttributeKind end
|
113
|
# File 'lib/ayril/xml_node.rb', line 113
def ; self.kind == NSXMLCommentKind end
|
#doc? ⇒ Boolean
103
|
# File 'lib/ayril/xml_node.rb', line 103
def doc?; self.kind == NSXMLDocumentKind end
|
#dtd? ⇒ Boolean
115
|
# File 'lib/ayril/xml_node.rb', line 115
def dtd?; self.kind == NSXMLDTDKind end
|
#elem? ⇒ Boolean
Also known as:
element?
105
|
# File 'lib/ayril/xml_node.rb', line 105
def elem?; self.kind == NSXMLElementKind end
|
#kind?(kind) ⇒ Boolean
Also known as:
type?
def self.namespaceWithName(name, stringValue: string) raise NotImplementedError end def self.DTDNodeWithXMLString(string) raise NotImplementedError end def self.predefinedNamespaceForPrefix(prefix) raise NotImplementedError end def self.processingInstructionWithName(name, stringValue: string) raise NotImplementedError end
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/ayril/xml_node.rb', line 91
def kind?(kind)
return self.kind == kind if kind.kind_of? Fixnum
kind = kind.to_sym
kinds = %w(invalid document element attribute namespace processing_instruction comment text DTD).invoke(:to_sym)
if kinds.include? kind
camelcase = kind.to_s.capitalize.gsub(/_([a-z])/) { |m| m[1].upcase }
return self.kind == Object.const_get(:"NSXML#{camelcase}Kind")
end
false
end
|
#namespace? ⇒ Boolean
111
|
# File 'lib/ayril/xml_node.rb', line 111
def namespace?; self.kind == NSXMLNamespaceKind end
|
#pi? ⇒ Boolean
112
|
# File 'lib/ayril/xml_node.rb', line 112
def pi?; self.kind == NSXMLProcessingInstructionKind end
|
#text? ⇒ Boolean
114
|
# File 'lib/ayril/xml_node.rb', line 114
def text?; self.kind == NSXMLTextKind end
|