Module: DiffXML

Defined in:
lib/diffxml.rb

Class Method Summary collapse

Class Method Details

.collectXPaths(doc) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/diffxml.rb', line 30

def self.collectXPaths(doc)
  doc.element_children.each do |child|
    if child.element_children.empty?
      @xpathArray.push(getPath(child,child.name)) unless child.content.empty?
    else
      collectXPaths(child)
    end
  end
end

.compareToPath(path, doc1, doc2) ⇒ Object



26
27
28
# File 'lib/diffxml.rb', line 26

def self.compareToPath(path, doc1, doc2)
  doc2.search(path, doc1.collect_namespaces).to_s == doc1.search(path, doc1.collect_namespaces).to_s
end

.compareXML(doc1, doc2) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/diffxml.rb', line 5

def self.compareXML(doc1, doc2)
  if doc1.class == Nokogiri::XML::Document
    collectXPaths(doc1.root)
  else
    collectXPaths(doc1)
  end
  @xpathArray.delete_if {|element| compareToPath(element,doc1, doc2)}
end

.getPath(node, path = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/diffxml.rb', line 14

def self.getPath(node, path = nil)
  if node.parent.name.eql? 'document'
    return path
  else
    if path.nil?
      getPath(node, node.name)
    else
      getPath(node.parent, "#{node.parent.name}/#{path}")
    end
  end
end

.getXPathArrayObject



40
41
42
# File 'lib/diffxml.rb', line 40

def self.getXPathArray
  @xpathArray
end