Class: Saxon::XML::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/saxon/xml.rb

Overview

Parse an XML File or String into a Document object

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xdm_document) ⇒ 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.



38
39
40
# File 'lib/saxon/xml.rb', line 38

def initialize(xdm_document)
  @xdm_document = xdm_document
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.

Parameters:

  • processor (Saxon::Processor)

    The processor object which should be used to build the document

  • string_or_io (String, File, IO)

    The input XML

  • opts (Hash) (defaults to: {})

    (see Saxon::SourceHelper#to_stream_source)

Returns:



23
24
25
26
27
28
# File 'lib/saxon/xml.rb', line 23

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)
end

Instance Method Details

#processorSaxon::Processor

Return the processor used to create this document

Returns:



55
56
57
# File 'lib/saxon/xml.rb', line 55

def processor
  Saxon::Processor.new(@xdm_document.processor)
end

#to_javanet.sf.saxon.s9api.XdmNode

Return the underlying Saxon document object

Returns:

  • (net.sf.saxon.s9api.XdmNode)

    return the underlying Saxon document object



44
45
46
# File 'lib/saxon/xml.rb', line 44

def to_java
  @xdm_document
end

#to_sString

Return a simple serialisation of the document

Returns:

  • (String)

    return a simple serialisation of the document



49
50
51
# File 'lib/saxon/xml.rb', line 49

def to_s
  @xdm_document.to_s
end

#xpath(expr) ⇒ net.sf.saxon.s9api.XdmValue

Return the value, node, or nodes selected

Parameters:

  • expr (String)

    The XPath expression to evaluate

Returns:

  • (net.sf.saxon.s9api.XdmValue)

    return the value, node, or nodes selected



33
34
35
# File 'lib/saxon/xml.rb', line 33

def xpath(expr)
  processor.to_java.new_xpath_compiler.evaluate(expr, @xdm_document)
end