Class: XML::SAX::Builder
- Defined in:
- lib/xml-sax-machines/builder.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
The document object.
Attributes inherited from Filter
Instance Method Summary collapse
-
#cdata_block(string) ⇒ Object
:nodoc:.
-
#characters(string) ⇒ Object
:nodoc:.
-
#comment(string) ⇒ Object
:nodoc:.
-
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
– TODO: Check namespace of context as well?.
-
#start_document ⇒ Object
:nodoc:.
- #start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = []) ⇒ Object
Methods inherited from Filter
#end_document, #error, #warning
Instance Attribute Details
#document ⇒ Object (readonly)
The document object.
Returns
Nokogiri::XML::Document
27 28 29 |
# File 'lib/xml-sax-machines/builder.rb', line 27 def document @document end |
Instance Method Details
#cdata_block(string) ⇒ Object
:nodoc:
66 67 68 69 |
# File 'lib/xml-sax-machines/builder.rb', line 66 def cdata_block(string) #:nodoc: super @context.add_child(Nokogiri::XML::CDATA.new(@document, string)) end |
#characters(string) ⇒ Object
:nodoc:
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/xml-sax-machines/builder.rb', line 55 def characters(string) #:nodoc: super # http://nokogiri.lighthouseapp.com/projects/19607-nokogiri/tickets/68-xpath-incorrect-when-text-siblings-exist#ticket-68-1 sibling = @context.children.last if sibling.kind_of?(Nokogiri::XML::Text) sibling.content += string else @context.add_child(Nokogiri::XML::Text.new(string, @document)) end end |
#comment(string) ⇒ Object
:nodoc:
71 72 73 74 |
# File 'lib/xml-sax-machines/builder.rb', line 71 def comment(string) #:nodoc: super @context.add_child(Nokogiri::XML::Comment.new(@document, string)) end |
#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object
– TODO: Check namespace of context as well?
48 49 50 51 52 53 |
# File 'lib/xml-sax-machines/builder.rb', line 48 def end_element_namespace(name, prefix = nil, uri = nil) super raise "Unmatched closing element. Got '#{name}' but expected '#{@context.name}'" \ unless name == @context.name @context = @context.parent end |
#start_document ⇒ Object
:nodoc:
29 30 31 32 33 |
# File 'lib/xml-sax-machines/builder.rb', line 29 def start_document #:nodoc: super @document = Nokogiri::XML::Document.new @context = @document end |
#start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xml-sax-machines/builder.rb', line 35 def start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = []) super el = Nokogiri::XML::Element.new(name, @document) el.namespace = el.add_namespace_definition(prefix, uri) if uri ns.each{|prefix, href| el.add_namespace_definition(prefix, href)} @context = @context.add_child(el) # Node needs to be added to the document so namespaces are available. attributes.each{|attribute| el[[attribute.prefix, attribute.localname].compact.join(':')] = attribute.value} end |