Class: Saxon::XML::Document
- Inherits:
-
Object
- Object
- Saxon::XML::Document
- Defined in:
- lib/saxon/xml.rb
Overview
Parse an XML File or String into a Document object
Instance Attribute Summary collapse
-
#processor ⇒ Saxon::Processor
readonly
Return the processor used to create this document.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(xdm_document, processor) ⇒ Document
constructor
private
A new instance of Document.
-
#to_java ⇒ net.sf.saxon.s9api.XdmNode
Return the underlying Saxon document object.
-
#to_s ⇒ String
Return a simple serialisation of the document.
-
#xpath(expr) ⇒ net.sf.saxon.s9api.XdmValue
Return the value, node, or nodes selected.
Constructor Details
#initialize(xdm_document, processor) ⇒ Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Document.
44 45 46 |
# File 'lib/saxon/xml.rb', line 44 def initialize(xdm_document, processor) @xdm_document, @processor = xdm_document, processor end |
Instance Attribute Details
#processor ⇒ Saxon::Processor (readonly)
Return the processor used to create this document
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/saxon/xml.rb', line 18 class Document # @api private # @param [Saxon::Processor] processor The processor object which should # be used to build the document # @param [String, File, IO] string_or_io The input XML # @param [Hash] opts (see Saxon::SourceHelper#to_stream_source) # @return [Saxon::XML::Document] def self.parse(processor, string_or_io, opts = {}) builder = processor.to_java.newDocumentBuilder() source = SourceHelper.to_stream_source(string_or_io, opts) xdm_document = builder.build(source) new(xdm_document, processor) end # @return [Saxon::Processor] return the processor used to create this # document attr_reader :processor # @param [String] expr The XPath expression to evaluate # @return [net.sf.saxon.s9api.XdmValue] return the value, node, or # nodes selected def xpath(expr) processor.to_java.new_xpath_compiler.evaluate(expr, @xdm_document) end # @api private def initialize(xdm_document, processor) @xdm_document, @processor = xdm_document, processor end # @return [net.sf.saxon.s9api.XdmNode] return the underlying Saxon # document object def to_java @xdm_document end # @return [String] return a simple serialisation of the document def to_s @xdm_document.to_s end end |
Class Method Details
.parse(processor, string_or_io, opts = {}) ⇒ Saxon::XML::Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 30 |
# File 'lib/saxon/xml.rb', line 25 def self.parse(processor, string_or_io, opts = {}) builder = processor.to_java.newDocumentBuilder() source = SourceHelper.to_stream_source(string_or_io, opts) xdm_document = builder.build(source) new(xdm_document, processor) end |
Instance Method Details
#to_java ⇒ net.sf.saxon.s9api.XdmNode
Return the underlying Saxon document object
50 51 52 |
# File 'lib/saxon/xml.rb', line 50 def to_java @xdm_document end |
#to_s ⇒ String
Return a simple serialisation of the document
55 56 57 |
# File 'lib/saxon/xml.rb', line 55 def to_s @xdm_document.to_s end |
#xpath(expr) ⇒ net.sf.saxon.s9api.XdmValue
Return the value, node, or nodes selected
39 40 41 |
# File 'lib/saxon/xml.rb', line 39 def xpath(expr) processor.to_java.new_xpath_compiler.evaluate(expr, @xdm_document) end |