libxml-ruby 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ /* $Id: ruby_xml_xpath.c 461 2008-07-15 21:35:56Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_xpath.h"
7
+ #include "ruby_xml_xpath_expression.h"
8
+
9
+ /*
10
+ * Document-class: LibXML::XML::XPath::Expression
11
+ *
12
+ * The XML::XPath::Expression class is used to compile
13
+ * XPath expressions so they can be parsed only once
14
+ * but reused multiple times.
15
+ *
16
+ * doc = XML::Document.string(IO.read('some xml file'))
17
+ * expr = XPath::Expression.new('//first')
18
+ * doc.root.each do |node|
19
+ * result = node.find(expr) # many, many, many times
20
+ * # ...
21
+ * end
22
+ */
23
+
24
+ VALUE cXMLXPathExpression;
25
+
26
+ void
27
+ ruby_xml_xpath_expression_free(xmlXPathCompExprPtr expr) {
28
+ xmlXPathFreeCompExpr(expr);
29
+ }
30
+
31
+ VALUE
32
+ ruby_xml_xpath_expression_alloc(VALUE klass) {
33
+ return Data_Wrap_Struct(cXMLXPathExpression,
34
+ NULL,
35
+ ruby_xml_xpath_expression_free,
36
+ NULL);
37
+ }
38
+
39
+ /* call-seq:
40
+ * XPath::Expression.new(expression) -> XPath::Expression
41
+ *
42
+ * Compiled XPatch expression. Work faster when find called many times
43
+ * same expression.
44
+ *
45
+ * doc = XML::Document.string('<header><first>hi</first></header>')
46
+ * expr = XPath::Expression.new('//first')
47
+ * nodes = doc.find(expr)
48
+ */
49
+ VALUE
50
+ ruby_xml_xpath_expression_initialize(VALUE self, VALUE expression) {
51
+ xmlXPathCompExprPtr compexpr = xmlXPathCompile(StringValueCStr(expression));
52
+
53
+ if (compexpr == NULL) {
54
+ xmlErrorPtr xerror = xmlGetLastError();
55
+ ruby_xml_raise(xerror);
56
+ }
57
+
58
+ DATA_PTR(self) = compexpr;
59
+ return self;
60
+ }
61
+
62
+ void
63
+ ruby_init_xml_xpath_expression(void) {
64
+ cXMLXPathExpression = rb_define_class_under(mXPath, "Expression", rb_cObject);
65
+ rb_define_alloc_func(cXMLXPathExpression, ruby_xml_xpath_expression_alloc);
66
+ rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, 1);
67
+
68
+ rb_define_method(cXMLXPathExpression, "initialize", ruby_xml_xpath_expression_initialize, 1);
69
+ }
@@ -0,0 +1,12 @@
1
+ /* $Id$ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_XPATH_EXPRESSION__
6
+ #define __RUBY_XML_XPATH_EXPRESSION__
7
+
8
+ extern VALUE cXMLXPathExpression;
9
+
10
+ void ruby_init_xml_xpath_expression(void);
11
+
12
+ #endif
data/ext/libxml/version.h CHANGED
@@ -1,9 +1,9 @@
1
1
  /* Don't nuke this block! It is used for automatically updating the
2
2
  * versions below. VERSION = string formatting, VERNUM = numbered
3
3
  * version for inline testing: increment both or none at all.*/
4
- #define RUBY_LIBXML_VERSION "0.9.1"
4
+ #define RUBY_LIBXML_VERSION "0.9.2"
5
5
  #define RUBY_LIBXML_VERNUM 0
6
6
  #define RUBY_LIBXML_VER_MAJ 0
7
7
  #define RUBY_LIBXML_VER_MIN 9
8
- #define RUBY_LIBXML_VER_MIC 1
8
+ #define RUBY_LIBXML_VER_MIC 2
9
9
  #define RUBY_LIBXML_VER_PATCH 0
@@ -63,7 +63,7 @@
63
63
  <Tool
64
64
  Name="VCLinkerTool"
65
65
  AdditionalDependencies="msvcrt-ruby18.lib libxml2.lib"
66
- OutputFile="C:\Development\ruby\lib\ruby\gems\1.8\gems\libxml-ruby-0.9.1-x86-mswin32-60\lib\$(ProjectName).so"
66
+ OutputFile="C:\Development\ruby\lib\ruby\gems\1.8\gems\libxml-ruby-0.9.2-x86-mswin32-60\lib\$(ProjectName).so"
67
67
  LinkIncremental="2"
68
68
  AdditionalLibraryDirectories="C:\Development\ruby\lib;C:\Development\msys\local\lib"
69
69
  GenerateDebugInformation="true"
@@ -273,6 +273,10 @@
273
273
  RelativePath="..\libxml\ruby_xml_xpath_context.c"
274
274
  >
275
275
  </File>
276
+ <File
277
+ RelativePath="..\libxml\ruby_xml_xpath_expression.c"
278
+ >
279
+ </File>
276
280
  <File
277
281
  RelativePath="..\libxml\ruby_xml_xpath_object.c"
278
282
  >
@@ -375,6 +379,10 @@
375
379
  RelativePath="..\libxml\ruby_xml_xpath_context.h"
376
380
  >
377
381
  </File>
382
+ <File
383
+ RelativePath="..\libxml\ruby_xml_xpath_expression.h"
384
+ >
385
+ </File>
378
386
  <File
379
387
  RelativePath="..\libxml\ruby_xml_xpath_object.h"
380
388
  >
@@ -143,4 +143,18 @@ class TestDocumentWrite < Test::Unit::TestCase
143
143
  assert_instance_of(XML::Node, @doc.root)
144
144
  assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<rubynet/>\n", @doc.to_s)
145
145
  end
146
+
147
+ def test_encoding_to_s
148
+ doc = XML::Document.new
149
+ doc.encoding = 'UTF-8'
150
+ doc.root = XML::Node.new 'node'
151
+ doc.root.content = '&#1;'
152
+
153
+ xml = doc.to_s(true, 'UTF-8')
154
+ puts xml
155
+
156
+ parser = XML::Parser.string(xml)
157
+ doc = parser.parse
158
+ p doc.root.content
159
+ end
146
160
  end
@@ -0,0 +1,35 @@
1
+ require "xml"
2
+ require 'test/unit'
3
+
4
+ class TestXPathExpression < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.new()
7
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
8
+ xp.string = str
9
+ @doc = xp.parse
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def nodes
17
+ expr = XML::XPath::Expression.compile('/ruby_array/fixnum')
18
+ @doc.find(expr)
19
+ end
20
+
21
+ def test_find_class
22
+ expr = XML::XPath::Expression.new('/ruby_array/fixnum')
23
+ set = @doc.find(expr)
24
+ assert_instance_of(XML::XPath::Object, set)
25
+ assert_equal(2, set.size)
26
+ end
27
+
28
+ def test_find_invalid
29
+ error = assert_raise(TypeError) do
30
+ set = @doc.find(999)
31
+ end
32
+ assert_equal('Argument should be an intance of a String or XPath::Expression',
33
+ error.to_s)
34
+ end
35
+ end
data/test/test_suite.rb CHANGED
@@ -24,6 +24,7 @@ require 'tc_traversal'
24
24
  require 'tc_well_formed'
25
25
  require 'tc_xinclude'
26
26
  require 'tc_xpath'
27
+ require 'tc_xpath_expression'
27
28
  require 'tc_xpointer'
28
29
 
29
30
  # Compatibility
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libxml-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-18 00:00:00 -07:00
12
+ date: 2008-11-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,6 +30,7 @@ files:
30
30
  - ext/libxml/cbg.c
31
31
  - ext/libxml/extconf.rb
32
32
  - ext/libxml/libxml.c
33
+ - ext/libxml/libxml.c.rej
33
34
  - ext/libxml/ruby_libxml.h
34
35
  - ext/libxml/ruby_xml_attr.c
35
36
  - ext/libxml/ruby_xml_attr.h
@@ -73,6 +74,8 @@ files:
73
74
  - ext/libxml/ruby_xml_xpath.h
74
75
  - ext/libxml/ruby_xml_xpath_context.c
75
76
  - ext/libxml/ruby_xml_xpath_context.h
77
+ - ext/libxml/ruby_xml_xpath_expression.c
78
+ - ext/libxml/ruby_xml_xpath_expression.h
76
79
  - ext/libxml/ruby_xml_xpath_object.c
77
80
  - ext/libxml/ruby_xml_xpath_object.h
78
81
  - ext/libxml/ruby_xml_xpointer.c
@@ -158,6 +161,7 @@ files:
158
161
  - test/tc_xml.rb
159
162
  - test/tc_xpath.rb
160
163
  - test/tc_xpath_context.rb
164
+ - test/tc_xpath_expression.rb
161
165
  - test/tc_xpointer.rb
162
166
  - test/test_suite.rb
163
167
  has_rdoc: true
@@ -218,4 +222,5 @@ test_files:
218
222
  - test/tc_xml.rb
219
223
  - test/tc_xpath.rb
220
224
  - test/tc_xpath_context.rb
225
+ - test/tc_xpath_expression.rb
221
226
  - test/tc_xpointer.rb