diffxml 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +48 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/diffxml.gemspec +26 -0
- data/lib/diffXML/diffxml.rb +39 -0
- data/rspec/diffXML_spec.rb +39 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f2b2a509890a18db793e9eaa3d277b78cdfc932
|
4
|
+
data.tar.gz: 681b21647b958bf7e0a9ac6877a2a8f4f18310fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d78f7f7650b321ce3dea3c274056851284d1831c76eb82efab2ab18c060335d0a9c32f2d40ba44a1fd5d4e85ba0d0cacd2db400f07998abcc9c038d821a2b4aa
|
7
|
+
data.tar.gz: 94823728ebedca927fed381d44853dbbecd27686c83cc4eb24ea7e28964c3b11f78618338d8e1f38fdb25693c5de953361f89029295b9e3dabe09addf41062d5
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.idea
|
4
|
+
/.config
|
5
|
+
/coverage/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/spec/examples.txt
|
10
|
+
/test/tmp/
|
11
|
+
/test/version_tmp/
|
12
|
+
/tmp/
|
13
|
+
|
14
|
+
## Specific to RubyMotion:
|
15
|
+
.dat*
|
16
|
+
.repl_history
|
17
|
+
build/
|
18
|
+
*.bridgesupport
|
19
|
+
build-iPhoneOS/
|
20
|
+
build-iPhoneSimulator/
|
21
|
+
|
22
|
+
## Specific to RubyMotion (use of CocoaPods):
|
23
|
+
#
|
24
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
25
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
26
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
27
|
+
#
|
28
|
+
# vendor/Pods/
|
29
|
+
|
30
|
+
## Documentation cache and generated files:
|
31
|
+
/.yardoc/
|
32
|
+
/_yardoc/
|
33
|
+
/doc/
|
34
|
+
/rdoc/
|
35
|
+
|
36
|
+
## Environment normalization:
|
37
|
+
/.bundle/
|
38
|
+
/vendor/bundle
|
39
|
+
/lib/bundler/man/
|
40
|
+
|
41
|
+
# for a library or gem, you might want to ignore these files since the code is
|
42
|
+
# intended to run in multiple environments; otherwise, check them in:
|
43
|
+
Gemfile.lock
|
44
|
+
.ruby-version
|
45
|
+
.ruby-gemset
|
46
|
+
|
47
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
48
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jake
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# diff-xml [](https://rubygems.org/gems/diffxml)
|
2
|
+
|
3
|
+
Inspired by the equivalent-xml gem, I wanted a way to get the differences between the two xmls, instead of just checking to see that there were differences, this is an alternative method I came up with, and I will add as I work on it, as it is still in its infancy.
|
4
|
+
|
5
|
+
## Disclaimer
|
6
|
+
|
7
|
+
This is an alternate method to a project I was working on, as such, there are no promises that it is the most efficient way to find the differences.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'diffxml'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install diffxml
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Pass two xml documents to the gem using
|
28
|
+
```ruby
|
29
|
+
DiffXML.compareXML(doc1, doc2)
|
30
|
+
```
|
31
|
+
the returned value will be an array with the XPaths of all nodes that were not matched.
|
32
|
+
|
33
|
+
## To Do
|
34
|
+
Plans to return the values of both nodes that are at the XPath in the array, as well as the XPath location are in the works.
|
35
|
+
General upkeep and a more rigorous test set are also planned.
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pbubnar/diff-xml.
|
40
|
+
|
data/Rakefile
ADDED
data/diffxml.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "diffxml"
|
7
|
+
spec.version = '0.1.1'
|
8
|
+
spec.authors = ["Jake Bubnar"]
|
9
|
+
spec.email = ["jake@pjbapps.com"]
|
10
|
+
spec.licenses = ["MIT"]
|
11
|
+
spec.summary = 'A simple xml comparison tool to get a list of diffs between two files passed to it'
|
12
|
+
spec.description = 'Goes through each child to find the XPaths of each final child, and compares them to the path in the second file'
|
13
|
+
spec.homepage = 'https://github.com/pbubnar/diffxml'
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
16
|
+
# delete this section to allow pushing this gem to any host.
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.test_files = ['rspec/diffXML_spec.rb']
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rspec", "~>3.4", ">= 3.4.0"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_runtime_dependency "nokogiri", "~> 1.6", ">= 1.6.7.2"
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'Nokogiri'
|
2
|
+
|
3
|
+
module DiffXML
|
4
|
+
@xpathArray = []
|
5
|
+
def self.compareXML(doc1, doc2)
|
6
|
+
if doc1.class == Nokogiri::XML::Document
|
7
|
+
collectXPaths(doc1.root)
|
8
|
+
else
|
9
|
+
collectXPaths(doc1)
|
10
|
+
end
|
11
|
+
@xpathArray.delete_if {|element| compareToPath(element,doc1, doc2)}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.getPath(node, path = nil)
|
15
|
+
if node.parent.name.eql? 'document'
|
16
|
+
return path
|
17
|
+
else
|
18
|
+
getPath(node.parent, "#{node.parent.name}/#{path}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.compareToPath(path, doc1, doc2)
|
23
|
+
doc2.search(path, doc1.collect_namespaces).to_s == doc1.search(path, doc1.collect_namespaces).to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.collectXPaths(doc)
|
27
|
+
doc.element_children.each do |child|
|
28
|
+
if child.element_children.empty?
|
29
|
+
@xpathArray.push(getPath(child,child.name)) unless child.content.empty?
|
30
|
+
else
|
31
|
+
collectXPaths(child)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.getXPathArray
|
37
|
+
@xpathArray
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'rspec'
|
3
|
+
require 'rspec/matchers'
|
4
|
+
require_relative '../lib/diffXML/diffxml'
|
5
|
+
|
6
|
+
describe DiffXML do
|
7
|
+
xml1 = Nokogiri::XML("<doc xmlns='foo:bar'><first>foo bar baz</first><second>things</second><third>
|
8
|
+
<firstthird><finalChild>asdf</finalChild></firstthird></third><fourth></fourth></doc>")
|
9
|
+
xml2 = Nokogiri::XML("<doc xmlns='foo:bar'><first>foo bar baz</first><second>things</second><third>
|
10
|
+
<firstthird><finalChild>asdf</finalChild></firstthird></third><fourth></fourth></doc>")
|
11
|
+
xml3 = Nokogiri::XML("<doc xmlns='foo:bar'><first>foo bar baz</first><second>things</second><third>
|
12
|
+
<firstthird><finalChild>asfd</finalChild></firstthird></third><fourth></fourth></doc>")
|
13
|
+
|
14
|
+
|
15
|
+
it 'should return an XPath for a given node' do
|
16
|
+
node = xml1.element_children[0].element_children[2].element_children[0].element_children[0]
|
17
|
+
expect(DiffXML.getPath(node, node.name)).to eql '/doc/third/firstthird/finalChild'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should Collect all XPaths of the children into an array' do
|
21
|
+
DiffXML.collectXPaths(xml1)
|
22
|
+
expect(DiffXML.getXPathArray.size).to be 3
|
23
|
+
expect(DiffXML.getXPathArray).to eql %w[/doc/first /doc/second /doc/third/firstthird/finalChild]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should retrieve and compare a node from a second document using a Path' do
|
27
|
+
expect(DiffXML.compareToPath('doc/first',xml1,xml2)).to eql true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should go through 2 XMLs removing XPaths from the array as they are found' do
|
31
|
+
expect(DiffXML.compareXML(xml1,xml2).size).to be 0
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return the differences in the event of a non match' do
|
35
|
+
expect(DiffXML.compareXML(xml1,xml3).size).to be 1
|
36
|
+
expect(DiffXML.getXPathArray[0].to_s).to eql 'doc/third/firstthird/finalChild'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diffxml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jake Bubnar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 3.4.0
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.4'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.4.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: nokogiri
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.6'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.6.7.2
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.6'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.6.7.2
|
81
|
+
description: Goes through each child to find the XPaths of each final child, and compares
|
82
|
+
them to the path in the second file
|
83
|
+
email:
|
84
|
+
- jake@pjbapps.com
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".DS_Store"
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- diffxml.gemspec
|
96
|
+
- lib/diffXML/diffxml.rb
|
97
|
+
- rspec/diffXML_spec.rb
|
98
|
+
homepage: https://github.com/pbubnar/diffxml
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.8
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: A simple xml comparison tool to get a list of diffs between two files passed
|
122
|
+
to it
|
123
|
+
test_files:
|
124
|
+
- rspec/diffXML_spec.rb
|