libxml-ruby 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +22 -0
- data/README +3 -1
- data/ext/libxml/cbg.c +86 -76
- data/ext/libxml/extconf.rb +2 -1
- data/ext/libxml/libxml.c +899 -885
- data/ext/libxml/ruby_libxml.h +65 -70
- data/ext/libxml/ruby_xml_attr.c +485 -500
- data/ext/libxml/ruby_xml_attributes.c +107 -106
- data/ext/libxml/ruby_xml_document.c +355 -356
- data/ext/libxml/ruby_xml_dtd.c +119 -117
- data/ext/libxml/ruby_xml_error.c +1112 -581
- data/ext/libxml/ruby_xml_html_parser.c +35 -34
- data/ext/libxml/ruby_xml_input.c +182 -187
- data/ext/libxml/ruby_xml_input_cbg.c +197 -179
- data/ext/libxml/ruby_xml_node.c +1529 -1566
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_ns.c +150 -156
- data/ext/libxml/ruby_xml_parser.c +37 -36
- data/ext/libxml/ruby_xml_parser_context.c +657 -659
- data/ext/libxml/ruby_xml_reader.c +203 -209
- data/ext/libxml/ruby_xml_relaxng.c +29 -25
- data/ext/libxml/ruby_xml_sax_parser.c +33 -32
- data/ext/libxml/ruby_xml_schema.c +165 -161
- data/ext/libxml/ruby_xml_state.c +19 -21
- data/ext/libxml/ruby_xml_xinclude.c +24 -25
- data/ext/libxml/ruby_xml_xpath.c +108 -108
- data/ext/libxml/ruby_xml_xpath_context.c +305 -293
- data/ext/libxml/ruby_xml_xpath_expression.c +24 -24
- data/ext/libxml/ruby_xml_xpath_object.c +89 -96
- data/ext/libxml/ruby_xml_xpointer.c +107 -109
- data/ext/libxml/ruby_xml_xpointer.h +13 -13
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/Rakefile +1 -1
- data/ext/vc/libxml_ruby.vcproj +1 -1
- data/lib/libxml/error.rb +4 -4
- data/test/tc_node_edit.rb +14 -2
- data/test/tc_node_text.rb +9 -9
- metadata +2 -2
@@ -1,12 +1,12 @@
|
|
1
1
|
#include "ruby_libxml.h"
|
2
2
|
#include "ruby_xml_relaxng.h"
|
3
3
|
|
4
|
-
/*
|
4
|
+
/*
|
5
5
|
* Document-class: LibXML::XML::RelaxNG
|
6
6
|
*
|
7
|
-
* The XML::RelaxNG class is used to prepare RelaxNG schemas for validation
|
7
|
+
* The XML::RelaxNG class is used to prepare RelaxNG schemas for validation
|
8
8
|
* of xml documents.
|
9
|
-
*
|
9
|
+
*
|
10
10
|
* Schemas can be created from XML documents, strings or URIs using the
|
11
11
|
* corresponding methods (new for URIs).
|
12
12
|
*
|
@@ -19,7 +19,7 @@
|
|
19
19
|
*
|
20
20
|
* # parse schema as xml document
|
21
21
|
* relaxng_document = XML::Document.file('schema.rng')
|
22
|
-
*
|
22
|
+
*
|
23
23
|
* # prepare schema for validation
|
24
24
|
* relaxng_schema = XML::RelaxNG.document(relaxng_document)
|
25
25
|
*
|
@@ -32,25 +32,25 @@
|
|
32
32
|
|
33
33
|
VALUE cXMLRelaxNG;
|
34
34
|
|
35
|
-
// Rdoc needs to know
|
35
|
+
// Rdoc needs to know
|
36
36
|
#ifdef RDOC_NEVER_DEFINED
|
37
|
-
|
38
|
-
|
37
|
+
mLibXML = rb_define_module("LibXML");
|
38
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
39
39
|
#endif
|
40
40
|
|
41
|
-
static void
|
42
|
-
|
41
|
+
static void rxml_relaxng_free(xmlRelaxNGPtr xrelaxng)
|
42
|
+
{
|
43
43
|
xmlRelaxNGFree(xrelaxng);
|
44
44
|
}
|
45
45
|
|
46
46
|
/*
|
47
47
|
* call-seq:
|
48
48
|
* XML::Relaxng.new(relaxng_uri) -> relaxng
|
49
|
-
*
|
49
|
+
*
|
50
50
|
* Create a new relaxng from the specified URI.
|
51
51
|
*/
|
52
|
-
static VALUE
|
53
|
-
|
52
|
+
static VALUE rxml_relaxng_init_from_uri(VALUE class, VALUE uri)
|
53
|
+
{
|
54
54
|
xmlRelaxNGParserCtxtPtr xparser;
|
55
55
|
xmlRelaxNGPtr xrelaxng;
|
56
56
|
|
@@ -66,11 +66,11 @@ rxml_relaxng_init_from_uri(VALUE class, VALUE uri) {
|
|
66
66
|
/*
|
67
67
|
* call-seq:
|
68
68
|
* XML::RelaxNG.document(document) -> relaxng
|
69
|
-
*
|
69
|
+
*
|
70
70
|
* Create a new relaxng from the specified document.
|
71
71
|
*/
|
72
|
-
static VALUE
|
73
|
-
|
72
|
+
static VALUE rxml_relaxng_init_from_document(VALUE class, VALUE document)
|
73
|
+
{
|
74
74
|
xmlDocPtr xdoc;
|
75
75
|
xmlRelaxNGPtr xrelaxng;
|
76
76
|
xmlRelaxNGParserCtxtPtr xparser;
|
@@ -87,27 +87,31 @@ rxml_relaxng_init_from_document(VALUE class, VALUE document) {
|
|
87
87
|
/*
|
88
88
|
* call-seq:
|
89
89
|
* XML::RelaxNG.string("relaxng_data") -> "value"
|
90
|
-
*
|
90
|
+
*
|
91
91
|
* Create a new relaxng using the specified string.
|
92
92
|
*/
|
93
|
-
static VALUE
|
94
|
-
|
95
|
-
xmlRelaxNGParserCtxtPtr
|
93
|
+
static VALUE rxml_relaxng_init_from_string(VALUE self, VALUE relaxng_str)
|
94
|
+
{
|
95
|
+
xmlRelaxNGParserCtxtPtr xparser;
|
96
96
|
xmlRelaxNGPtr xrelaxng;
|
97
97
|
|
98
98
|
Check_Type(relaxng_str, T_STRING);
|
99
99
|
|
100
|
-
xparser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), strlen(
|
100
|
+
xparser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), strlen(
|
101
|
+
StringValuePtr(relaxng_str)));
|
101
102
|
xrelaxng = xmlRelaxNGParse(xparser);
|
102
103
|
xmlRelaxNGFreeParserCtxt(xparser);
|
103
104
|
|
104
105
|
return Data_Wrap_Struct(cXMLRelaxNG, NULL, rxml_relaxng_free, xrelaxng);
|
105
106
|
}
|
106
|
-
|
107
|
-
void ruby_init_xml_relaxng(void)
|
107
|
+
|
108
|
+
void ruby_init_xml_relaxng(void)
|
109
|
+
{
|
108
110
|
cXMLRelaxNG = rb_define_class_under(mXML, "RelaxNG", rb_cObject);
|
109
|
-
rb_define_singleton_method(cXMLRelaxNG, "new",
|
110
|
-
rb_define_singleton_method(cXMLRelaxNG, "from_string",
|
111
|
-
|
111
|
+
rb_define_singleton_method(cXMLRelaxNG, "new", rxml_relaxng_init_from_uri, 1);
|
112
|
+
rb_define_singleton_method(cXMLRelaxNG, "from_string",
|
113
|
+
rxml_relaxng_init_from_string, 1);
|
114
|
+
rb_define_singleton_method(cXMLRelaxNG, "document",
|
115
|
+
rxml_relaxng_init_from_document, 1);
|
112
116
|
}
|
113
117
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_sax_parser.c
|
1
|
+
/* $Id: ruby_xml_sax_parser.c 650 2008-11-30 03:40:22Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -10,15 +10,15 @@
|
|
10
10
|
*
|
11
11
|
* XML::SaxParser provides a callback based API for parsing documents,
|
12
12
|
* in contrast to XML::Parser's tree based API and XML::Reader's stream
|
13
|
-
* based API.
|
13
|
+
* based API.
|
14
14
|
*
|
15
|
-
* Note that the XML::SaxParser API is fairly complex, not well standardized,
|
15
|
+
* Note that the XML::SaxParser API is fairly complex, not well standardized,
|
16
16
|
* and does not directly support validation making entity, namespace and
|
17
17
|
* base processing relatively hard.
|
18
18
|
*
|
19
19
|
* To use the XML::SaxParser, register a callback class via the
|
20
|
-
* XML::SaxParser#callbacks=. It is easiest to include the
|
21
|
-
* XML::SaxParser::Callbacks module in your class and override
|
20
|
+
* XML::SaxParser#callbacks=. It is easiest to include the
|
21
|
+
* XML::SaxParser::Callbacks module in your class and override
|
22
22
|
* the methods as needed.
|
23
23
|
*
|
24
24
|
* Basic example:
|
@@ -64,54 +64,55 @@ VALUE cbidOnExternalSubset;
|
|
64
64
|
/*
|
65
65
|
* call-seq:
|
66
66
|
* sax_parser.initialize -> sax_parser
|
67
|
-
*
|
67
|
+
*
|
68
68
|
* Initiliazes instance of parser.
|
69
69
|
*/
|
70
|
-
static VALUE
|
71
|
-
|
70
|
+
static VALUE rxml_sax_parser_initialize(VALUE self)
|
71
|
+
{
|
72
72
|
VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
|
73
73
|
rb_iv_set(self, "@input", input);
|
74
74
|
return self;
|
75
75
|
}
|
76
76
|
|
77
|
-
|
78
77
|
/* Parsing data sources */
|
79
|
-
static int
|
80
|
-
|
78
|
+
static int rxml_sax_parser_parse_file(VALUE self, VALUE input)
|
79
|
+
{
|
81
80
|
VALUE file = rb_ivar_get(input, FILE_ATTR);
|
82
|
-
return xmlSAXUserParseFile((xmlSAXHandlerPtr)&rxml_sax_hander_struct,
|
81
|
+
return xmlSAXUserParseFile((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
|
82
|
+
(void *) self, StringValuePtr(file));
|
83
83
|
}
|
84
84
|
|
85
|
-
static int
|
86
|
-
|
85
|
+
static int rxml_sax_parser_parse_string(VALUE self, VALUE input)
|
86
|
+
{
|
87
87
|
VALUE str = rb_ivar_get(input, STRING_ATTR);
|
88
|
-
return xmlSAXUserParseMemory((xmlSAXHandlerPtr)&rxml_sax_hander_struct,
|
88
|
+
return xmlSAXUserParseMemory((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
|
89
|
+
(void *) self, StringValuePtr(str), RSTRING_LEN(str));
|
89
90
|
}
|
90
91
|
|
91
|
-
static int
|
92
|
-
|
92
|
+
static int rxml_sax_parser_parse_io(VALUE self, VALUE input)
|
93
|
+
{
|
93
94
|
VALUE io = rb_ivar_get(input, IO_ATTR);
|
94
95
|
VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
|
95
96
|
xmlCharEncoding xmlEncoding = NUM2INT(encoding);
|
96
|
-
xmlParserCtxtPtr ctxt =
|
97
|
-
|
98
|
-
|
97
|
+
xmlParserCtxtPtr ctxt =
|
98
|
+
xmlCreateIOParserCtxt((xmlSAXHandlerPtr) & rxml_sax_hander_struct,
|
99
|
+
(void *) self, (xmlInputReadCallback) rxml_read_callback, NULL,
|
100
|
+
(void *) io, xmlEncoding);
|
99
101
|
return xmlParseDocument(ctxt);
|
100
102
|
}
|
101
103
|
|
102
|
-
|
103
104
|
/*
|
104
105
|
* call-seq:
|
105
106
|
* parser.parse -> (true|false)
|
106
|
-
*
|
107
|
+
*
|
107
108
|
* Parse the input XML, generating callbacks to the object
|
108
109
|
* registered via the +callbacks+ attributesibute.
|
109
110
|
*/
|
110
|
-
static VALUE
|
111
|
-
|
111
|
+
static VALUE rxml_sax_parser_parse(VALUE self)
|
112
|
+
{
|
112
113
|
int status;
|
113
114
|
VALUE input = rb_ivar_get(self, INPUT_ATTR);
|
114
|
-
|
115
|
+
|
115
116
|
if (rb_ivar_get(input, FILE_ATTR) != Qnil)
|
116
117
|
status = rxml_sax_parser_parse_file(self, input);
|
117
118
|
else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
|
@@ -120,7 +121,7 @@ rxml_sax_parser_parse(VALUE self) {
|
|
120
121
|
status = rxml_sax_parser_parse_io(self, input);
|
121
122
|
else
|
122
123
|
rb_raise(rb_eArgError, "You must specify a parser data source");
|
123
|
-
|
124
|
+
|
124
125
|
if (status)
|
125
126
|
{
|
126
127
|
rxml_raise(&xmlLastError);
|
@@ -128,18 +129,18 @@ rxml_sax_parser_parse(VALUE self) {
|
|
128
129
|
}
|
129
130
|
else
|
130
131
|
{
|
131
|
-
return(Qtrue);
|
132
|
+
return (Qtrue);
|
132
133
|
}
|
133
134
|
}
|
134
135
|
|
135
|
-
// Rdoc needs to know
|
136
|
+
// Rdoc needs to know
|
136
137
|
#ifdef RDOC_NEVER_DEFINED
|
137
|
-
|
138
|
-
|
138
|
+
mLibXML = rb_define_module("LibXML");
|
139
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
139
140
|
#endif
|
140
141
|
|
141
|
-
void
|
142
|
-
|
142
|
+
void ruby_init_xml_sax_parser(void)
|
143
|
+
{
|
143
144
|
/* SaxParser */
|
144
145
|
cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
|
145
146
|
|
@@ -1,161 +1,165 @@
|
|
1
|
-
#include "ruby_libxml.h"
|
2
|
-
#include "ruby_xml_schema.h"
|
3
|
-
|
4
|
-
/*
|
5
|
-
* Document-class: LibXML::XML::Schema
|
6
|
-
*
|
7
|
-
* The XML::Schema class is used to prepare XML Schemas for validation of xml
|
8
|
-
* documents.
|
9
|
-
*
|
10
|
-
* Schemas can be created from XML documents, strings or URIs using the
|
11
|
-
* corresponding methods (new for URIs).
|
12
|
-
*
|
13
|
-
* Once a schema is prepared, an XML document can be validated by the
|
14
|
-
* XML::Document#validate_schema method providing the XML::Schema object
|
15
|
-
* as parameter. The method return true if the document validates, false
|
16
|
-
* otherwise.
|
17
|
-
*
|
18
|
-
* Basic usage:
|
19
|
-
*
|
20
|
-
* # parse schema as xml document
|
21
|
-
* schema_document = XML::Document.file('schema.rng')
|
22
|
-
*
|
23
|
-
* # prepare schema for validation
|
24
|
-
* schema = XML::Schema.document(schema_document)
|
25
|
-
*
|
26
|
-
* # parse xml document to be validated
|
27
|
-
* instance = XML::Document.file('instance.xml')
|
28
|
-
*
|
29
|
-
* # validate
|
30
|
-
* instance.validate_schema(schema)
|
31
|
-
*/
|
32
|
-
|
33
|
-
VALUE cXMLSchema;
|
34
|
-
|
35
|
-
// Rdoc needs to know
|
36
|
-
#ifdef RDOC_NEVER_DEFINED
|
37
|
-
|
38
|
-
|
39
|
-
#endif
|
40
|
-
|
41
|
-
static void
|
42
|
-
|
43
|
-
xmlSchemaFree(xschema);
|
44
|
-
}
|
45
|
-
|
46
|
-
/*
|
47
|
-
* call-seq:
|
48
|
-
* XML::Schema.initialize(schema_uri) -> schema
|
49
|
-
*
|
50
|
-
* Create a new schema from the specified URI.
|
51
|
-
*/
|
52
|
-
static VALUE
|
53
|
-
|
54
|
-
xmlSchemaParserCtxtPtr xparser;
|
55
|
-
xmlSchemaPtr xschema;
|
56
|
-
|
57
|
-
Check_Type(uri, T_STRING);
|
58
|
-
|
59
|
-
xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
|
60
|
-
xschema = xmlSchemaParse(xparser);
|
61
|
-
xmlSchemaFreeParserCtxt(xparser);
|
62
|
-
|
63
|
-
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
64
|
-
}
|
65
|
-
|
66
|
-
/*
|
67
|
-
* call-seq:
|
68
|
-
* XML::Schema.document(document) -> schema
|
69
|
-
*
|
70
|
-
* Create a new schema from the specified document.
|
71
|
-
*/
|
72
|
-
static VALUE
|
73
|
-
|
74
|
-
xmlDocPtr xdoc;
|
75
|
-
xmlSchemaPtr xschema;
|
76
|
-
xmlSchemaParserCtxtPtr xparser;
|
77
|
-
|
78
|
-
Data_Get_Struct(document, xmlDoc, xdoc);
|
79
|
-
|
80
|
-
xparser = xmlSchemaNewDocParserCtxt(xdoc);
|
81
|
-
xschema = xmlSchemaParse(xparser);
|
82
|
-
xmlSchemaFreeParserCtxt(xparser);
|
83
|
-
|
84
|
-
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
85
|
-
}
|
86
|
-
|
87
|
-
/*
|
88
|
-
* call-seq:
|
89
|
-
* XML::Schema.string("schema_data") -> "value"
|
90
|
-
*
|
91
|
-
* Create a new schema using the specified string.
|
92
|
-
*/
|
93
|
-
static VALUE
|
94
|
-
|
95
|
-
xmlSchemaParserCtxtPtr
|
96
|
-
xmlSchemaPtr xschema;
|
97
|
-
|
98
|
-
Check_Type(schema_str, T_STRING);
|
99
|
-
|
100
|
-
xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
+
|
141
|
-
|
142
|
-
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
rb_define_singleton_method(cXMLSchema, "
|
160
|
-
|
161
|
-
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_schema.h"
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Document-class: LibXML::XML::Schema
|
6
|
+
*
|
7
|
+
* The XML::Schema class is used to prepare XML Schemas for validation of xml
|
8
|
+
* documents.
|
9
|
+
*
|
10
|
+
* Schemas can be created from XML documents, strings or URIs using the
|
11
|
+
* corresponding methods (new for URIs).
|
12
|
+
*
|
13
|
+
* Once a schema is prepared, an XML document can be validated by the
|
14
|
+
* XML::Document#validate_schema method providing the XML::Schema object
|
15
|
+
* as parameter. The method return true if the document validates, false
|
16
|
+
* otherwise.
|
17
|
+
*
|
18
|
+
* Basic usage:
|
19
|
+
*
|
20
|
+
* # parse schema as xml document
|
21
|
+
* schema_document = XML::Document.file('schema.rng')
|
22
|
+
*
|
23
|
+
* # prepare schema for validation
|
24
|
+
* schema = XML::Schema.document(schema_document)
|
25
|
+
*
|
26
|
+
* # parse xml document to be validated
|
27
|
+
* instance = XML::Document.file('instance.xml')
|
28
|
+
*
|
29
|
+
* # validate
|
30
|
+
* instance.validate_schema(schema)
|
31
|
+
*/
|
32
|
+
|
33
|
+
VALUE cXMLSchema;
|
34
|
+
|
35
|
+
// Rdoc needs to know
|
36
|
+
#ifdef RDOC_NEVER_DEFINED
|
37
|
+
mLibXML = rb_define_module("LibXML");
|
38
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
39
|
+
#endif
|
40
|
+
|
41
|
+
static void rxml_schema_free(xmlSchemaPtr xschema)
|
42
|
+
{
|
43
|
+
xmlSchemaFree(xschema);
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* call-seq:
|
48
|
+
* XML::Schema.initialize(schema_uri) -> schema
|
49
|
+
*
|
50
|
+
* Create a new schema from the specified URI.
|
51
|
+
*/
|
52
|
+
static VALUE rxml_schema_init_from_uri(VALUE class, VALUE uri)
|
53
|
+
{
|
54
|
+
xmlSchemaParserCtxtPtr xparser;
|
55
|
+
xmlSchemaPtr xschema;
|
56
|
+
|
57
|
+
Check_Type(uri, T_STRING);
|
58
|
+
|
59
|
+
xparser = xmlSchemaNewParserCtxt(StringValuePtr(uri));
|
60
|
+
xschema = xmlSchemaParse(xparser);
|
61
|
+
xmlSchemaFreeParserCtxt(xparser);
|
62
|
+
|
63
|
+
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* call-seq:
|
68
|
+
* XML::Schema.document(document) -> schema
|
69
|
+
*
|
70
|
+
* Create a new schema from the specified document.
|
71
|
+
*/
|
72
|
+
static VALUE rxml_schema_init_from_document(VALUE class, VALUE document)
|
73
|
+
{
|
74
|
+
xmlDocPtr xdoc;
|
75
|
+
xmlSchemaPtr xschema;
|
76
|
+
xmlSchemaParserCtxtPtr xparser;
|
77
|
+
|
78
|
+
Data_Get_Struct(document, xmlDoc, xdoc);
|
79
|
+
|
80
|
+
xparser = xmlSchemaNewDocParserCtxt(xdoc);
|
81
|
+
xschema = xmlSchemaParse(xparser);
|
82
|
+
xmlSchemaFreeParserCtxt(xparser);
|
83
|
+
|
84
|
+
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
85
|
+
}
|
86
|
+
|
87
|
+
/*
|
88
|
+
* call-seq:
|
89
|
+
* XML::Schema.string("schema_data") -> "value"
|
90
|
+
*
|
91
|
+
* Create a new schema using the specified string.
|
92
|
+
*/
|
93
|
+
static VALUE rxml_schema_init_from_string(VALUE self, VALUE schema_str)
|
94
|
+
{
|
95
|
+
xmlSchemaParserCtxtPtr xparser;
|
96
|
+
xmlSchemaPtr xschema;
|
97
|
+
|
98
|
+
Check_Type(schema_str, T_STRING);
|
99
|
+
|
100
|
+
xparser = xmlSchemaNewMemParserCtxt(StringValuePtr(schema_str), strlen(
|
101
|
+
StringValuePtr(schema_str)));
|
102
|
+
xschema = xmlSchemaParse(xparser);
|
103
|
+
xmlSchemaFreeParserCtxt(xparser);
|
104
|
+
|
105
|
+
return Data_Wrap_Struct(cXMLSchema, NULL, rxml_schema_free, xschema);
|
106
|
+
}
|
107
|
+
|
108
|
+
/* TODO what is this patch doing here?
|
109
|
+
|
110
|
+
xmlSchemaParserCtxtPtr parser;
|
111
|
+
xmlSchemaPtr sptr;
|
112
|
+
xmlSchemaValidCtxtPtr vptr;
|
113
|
+
+ int is_invalid;
|
114
|
+
|
115
|
+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &source) == FAILURE) {
|
116
|
+
return;
|
117
|
+
@@ -598,26 +598,24 @@
|
118
|
+
convert_to_string_ex(&source);
|
119
|
+
parser = xmlSchemaNewParserCtxt(Z_STRVAL_P(source));
|
120
|
+
sptr = xmlSchemaParse(parser);
|
121
|
+
break;
|
122
|
+
case SCHEMA_BLOB:
|
123
|
+
convert_to_string_ex(&source);
|
124
|
+
parser = xmlSchemaNewMemParserCtxt(Z_STRVAL_P(source), Z_STRLEN_P(source));
|
125
|
+
sptr = xmlSchemaParse(parser);
|
126
|
+
break;
|
127
|
+
}
|
128
|
+
|
129
|
+
vptr = xmlSchemaNewValidCtxt(sptr);
|
130
|
+
+ is_invalid = xmlSchemaValidateDoc(vptr, (xmlDocPtr) sxe->document->ptr);
|
131
|
+
xmlSchemaFree(sptr);
|
132
|
+
xmlSchemaFreeValidCtxt(vptr);
|
133
|
+
xmlSchemaFreeParserCtxt(parser);
|
134
|
+
|
135
|
+
- if (is_valid) {
|
136
|
+
- RETURN_TRUE;
|
137
|
+
- } else {
|
138
|
+
+ if (is_invalid) {
|
139
|
+
RETURN_FALSE;
|
140
|
+
+ } else {
|
141
|
+
+ RETURN_TRUE;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
}}}
|
145
|
+
@@ -695,7 +693,7 @@
|
146
|
+
{
|
147
|
+
if (!strcmp(method, "xsearch")) {
|
148
|
+
simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
149
|
+
-#ifdef xmlSchemaParserCtxtPtr
|
150
|
+
+#ifdef LIBXML_SCHEMAS_ENABLED
|
151
|
+
} else if (!strcmp(method, "validate_schema_file")) {
|
152
|
+
simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAM_PASSTHRU, SCHEMA_FILE);
|
153
|
+
} else if (!strcmp(method, "validate_schema_buffer")) {
|
154
|
+
*/
|
155
|
+
|
156
|
+
void ruby_init_xml_schema(void)
|
157
|
+
{
|
158
|
+
cXMLSchema = rb_define_class_under(mXML, "Schema", rb_cObject);
|
159
|
+
rb_define_singleton_method(cXMLSchema, "new", rxml_schema_init_from_uri, 1);
|
160
|
+
rb_define_singleton_method(cXMLSchema, "from_string",
|
161
|
+
rxml_schema_init_from_string, 1);
|
162
|
+
rb_define_singleton_method(cXMLSchema, "document",
|
163
|
+
rxml_schema_init_from_document, 1);
|
164
|
+
}
|
165
|
+
|