├── lib ├── 1.8 │ └── .gitignore ├── 1.9 │ └── .gitignore ├── 2.0 │ └── .gitignore ├── libs │ ├── libz.dll │ ├── libiconv-2.dll │ └── libxml2-2.dll ├── xml │ └── libxml.rb ├── libxml │ ├── attributes.rb │ ├── schema │ │ ├── attribute.rb │ │ ├── element.rb │ │ └── type.rb │ ├── xpath_object.rb │ ├── properties.rb │ ├── ns.rb │ ├── reader.rb │ ├── tree.rb │ ├── namespaces.rb │ ├── namespace.rb │ ├── sax_parser.rb │ ├── attr_decl.rb │ ├── hpricot.rb │ ├── schema.rb │ ├── error.rb │ ├── attr.rb │ └── html_parser.rb ├── xml.rb └── libxml.rb ├── test ├── c14n │ ├── given │ │ ├── world.txt │ │ ├── doc.dtd │ │ ├── example-6.xml │ │ ├── example-2.xml │ │ ├── example-1.xml │ │ ├── example-7.xml │ │ ├── example-8.xpath │ │ ├── example-8.xml │ │ ├── example-5.xml │ │ ├── example-4.xml │ │ └── example-3.xml │ └── result │ │ ├── with-comments │ │ ├── example-6 │ │ ├── example-7 │ │ ├── example-5 │ │ ├── example-1 │ │ ├── example-2 │ │ ├── example-4 │ │ └── example-3 │ │ ├── without-comments │ │ ├── example-6 │ │ ├── example-5 │ │ ├── example-1 │ │ ├── example-7 │ │ ├── example-2 │ │ ├── example-4 │ │ └── example-3 │ │ └── 1-1-without-comments │ │ ├── example-6 │ │ ├── example-5 │ │ ├── example-1 │ │ ├── example-7 │ │ ├── example-8 │ │ ├── example-2 │ │ ├── example-4 │ │ └── example-3 ├── ets_test.xml ├── model │ ├── rubynet_project │ ├── bands.iso-8859-1.xml │ ├── xinclude.xml │ ├── bands.xml │ ├── bands.utf-8.xml │ ├── atom.xml │ ├── shiporder.xml │ ├── shiporder.rnc │ ├── soap.xml │ ├── shiporder.xsd │ ├── merge_bug_data.xml │ ├── shiporder.rng │ └── rubynet.xml ├── ets_tsr.rb ├── test_helper.rb ├── tc_deprecated_require.rb ├── ets_doc_file.rb ├── etc_doc_to_s.rb ├── ets_doc_to_s.rb ├── ets_node_gc.rb ├── ets_gpx.rb ├── tc_html_parser_context.rb ├── tc_xinclude.rb ├── tc_node_xlink.rb ├── tc_node_comment.rb ├── tc_node_pi.rb ├── tc_node_copy.rb ├── tc_xpath_expression.rb ├── tc_properties.rb ├── test_suite.rb ├── tc_node_cdata.rb ├── tc_relaxng.rb ├── tc_namespace.rb ├── tc_node_text.rb ├── tc_xpointer.rb ├── tc_xpath_context.rb ├── tc_encoding_sax.rb ├── tc_traversal.rb ├── tc_document.rb ├── tc_attr_decl.rb ├── tc_html_parser.rb ├── tc_attributes.rb ├── tc_dtd.rb └── tc_encoding.rb ├── website ├── .htaccess ├── .rsync-filter ├── img │ ├── raze-tiny.png │ ├── red-cube.jpg │ └── xml-ruby.png ├── _config.yml ├── _includes │ ├── footer.html │ ├── header.html │ └── sidebar.html ├── _layouts │ ├── post.html │ └── base.html ├── README.markdown ├── _posts │ └── 2010-06-29-license.markdown └── css │ └── normal.css ├── ext ├── libxml │ ├── .gitignore │ ├── ruby_xml_dtd.h │ ├── ruby_xml_relaxng.h │ ├── ruby_xml_writer.h │ ├── ruby_xml_schema_type.h │ ├── ruby_xml_namespaces.h │ ├── ruby_xml.h │ ├── ruby_xml_sax_parser.h │ ├── ruby_xml_html_parser.h │ ├── ruby_xml_xpath_context.h │ ├── ruby_xml_parser_context.h │ ├── ruby_xml_sax2_handler.h │ ├── ruby_xml_parser.h │ ├── ruby_xml_xinclude.h │ ├── ruby_xml_xpath_expression.h │ ├── ruby_xml_namespace.h │ ├── ruby_xml_html_parser_context.h │ ├── ruby_xml_html_parser_options.h │ ├── ruby_xml_node.h │ ├── ruby_xml_xpointer.h │ ├── ruby_xml_document.h │ ├── ruby_xml_error.h │ ├── ruby_xml_parser_options.h │ ├── ruby_xml_io.h │ ├── ruby_xml_attr_decl.h │ ├── ruby_xml_xpath.h │ ├── ruby_xml_attr.h │ ├── ruby_xml_schema_facet.h │ ├── ruby_xml_xinclude.c │ ├── ruby_xml_schema_element.h │ ├── ruby_xml_xpath_object.h │ ├── ruby_xml_input_cbg.h │ ├── ruby_xml_schema_attribute.h │ ├── ruby_xml_version.h │ ├── ruby_xml_attributes.h │ ├── ruby_xml_reader.h │ ├── ruby_xml_encoding.h │ ├── libxml_ruby.def │ ├── ruby_xml_schema_facet.c │ ├── ruby_xml_io.c │ ├── ruby_xml_html_parser_options.c │ ├── libxml.c │ ├── ruby_libxml.h │ ├── ruby_xml_cbg.c │ ├── ruby_xml_xpath_expression.c │ ├── ruby_xml_schema_element.c │ ├── ruby_xml_html_parser.c │ ├── ruby_xml_parser.c │ ├── ruby_xml_xpointer.c │ ├── ruby_xml_parser_options.c │ ├── extconf.rb │ ├── ruby_xml_relaxng.c │ ├── ruby_xml_schema_attribute.c │ ├── ruby_xml_sax_parser.c │ ├── ruby_xml_attr_decl.c │ └── ruby_xml_namespace.c └── vc │ ├── libxml_ruby_18 │ └── libxml_ruby.vcxproj.user │ ├── libxml_ruby_19 │ └── libxml_ruby_19.vcxproj.user │ └── libxml_ruby.sln ├── .gitmodules ├── script ├── test └── benchmark │ └── throughput ├── .gitignore ├── LICENSE ├── log └── changelog.xsl ├── libxml-ruby.gemspec ├── Rakefile └── MANIFEST /lib/1.8/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.so -------------------------------------------------------------------------------- /lib/1.9/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.so -------------------------------------------------------------------------------- /test/c14n/given/world.txt: -------------------------------------------------------------------------------- 1 | world -------------------------------------------------------------------------------- /lib/2.0/.gitignore: -------------------------------------------------------------------------------- 1 | /libxml_ruby.so 2 | -------------------------------------------------------------------------------- /test/c14n/given/doc.dtd: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-6: -------------------------------------------------------------------------------- 1 | © -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-6: -------------------------------------------------------------------------------- 1 | © -------------------------------------------------------------------------------- /test/ets_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-6: -------------------------------------------------------------------------------- 1 | © -------------------------------------------------------------------------------- /website/.htaccess: -------------------------------------------------------------------------------- 1 | DirectoryIndex index.xml index.html 2 | 3 | -------------------------------------------------------------------------------- /ext/libxml/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.a 4 | *.log 5 | extconf.h 6 | Makefile -------------------------------------------------------------------------------- /test/model/rubynet_project: -------------------------------------------------------------------------------- 1 | This is some text to include in an xml file via XInclude. -------------------------------------------------------------------------------- /lib/libs/libz.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/lib/libs/libz.dll -------------------------------------------------------------------------------- /lib/libs/libiconv-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/lib/libs/libiconv-2.dll -------------------------------------------------------------------------------- /lib/libs/libxml2-2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/lib/libs/libxml2-2.dll -------------------------------------------------------------------------------- /test/c14n/given/example-6.xml: -------------------------------------------------------------------------------- 1 | 2 | © 3 | -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-5: -------------------------------------------------------------------------------- 1 | 2 | Hello, world! 3 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-5: -------------------------------------------------------------------------------- 1 | 2 | Hello, world! 3 | -------------------------------------------------------------------------------- /website/.rsync-filter: -------------------------------------------------------------------------------- 1 | - .svn 2 | P wiki 3 | P robot.txt 4 | P statcvs 5 | P statsvn 6 | P usage 7 | 8 | -------------------------------------------------------------------------------- /website/img/raze-tiny.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/website/img/raze-tiny.png -------------------------------------------------------------------------------- /website/img/red-cube.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/website/img/red-cube.jpg -------------------------------------------------------------------------------- /website/img/xml-ruby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/website/img/xml-ruby.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "website/_site"] 2 | path = website/_site 3 | url = git@github.com:xml4r/libxml-ruby.git 4 | -------------------------------------------------------------------------------- /test/model/bands.iso-8859-1.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sferik/libxml-ruby/master/test/model/bands.iso-8859-1.xml -------------------------------------------------------------------------------- /website/_config.yml: -------------------------------------------------------------------------------- 1 | auto: true 2 | server: true 3 | pygments: true 4 | permalink: none 5 | exclude: README.markdown 6 | -------------------------------------------------------------------------------- /website/_includes/footer.html: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /script/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | %w{test lib ext/libxml}.each{ |path| $LOAD_PATH.unshift(path) } 4 | 5 | load './test/test_suite.rb' 6 | 7 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-7: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-1: -------------------------------------------------------------------------------- 1 | 3 | Hello, world! 4 | -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-7: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-1: -------------------------------------------------------------------------------- 1 | 3 | Hello, world! 4 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-7: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-5: -------------------------------------------------------------------------------- 1 | 2 | Hello, world! 3 | 4 | -------------------------------------------------------------------------------- /website/_includes/header.html: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /lib/xml/libxml.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # This is here for backward compatibility. 4 | # 5 | # TODO: DEPRECATE! 6 | 7 | require 'libxml.rb' 8 | 9 | include LibXML 10 | 11 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-8: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_dtd.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_DTD__ 2 | #define __RXML_DTD__ 3 | 4 | extern VALUE cXMLDtd; 5 | 6 | void rxml_init_dtd(void); 7 | VALUE rxml_dtd_wrap(xmlDtdPtr xdtd); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-1: -------------------------------------------------------------------------------- 1 | 3 | Hello, world! 4 | 5 | 6 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_relaxng.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_RELAXNG__ 2 | #define __RXML_RELAXNG__ 3 | 4 | #include 5 | 6 | extern VALUE cXMLRelaxNG; 7 | 8 | void rxml_init_relaxng(void); 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_writer.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_WRITER__ 2 | #define __RXML_WRITER__ 3 | 4 | #ifdef LIBXML_WRITER_ENABLED 5 | #include 6 | #endif 7 | 8 | extern VALUE cXMLWriter; 9 | void rxml_init_writer(void); 10 | #endif 11 | -------------------------------------------------------------------------------- /test/c14n/given/example-2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | A B 4 | 5 | A 6 | 7 | B 8 | A B 9 | C 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/ets_tsr.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | 10_000.times {|n| 6 | j=XML::Node.new2(nil,"happy#{n}") 7 | 10.times {|r| 8 | j1=XML::Node.new("happy#{r}","farts") 9 | j.child=j1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_schema_type.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_SCHEMA_TYPE__ 2 | #define __RXML_SCHEMA_TYPE__ 3 | 4 | extern VALUE cXMLSchemaType; 5 | 6 | VALUE rxml_wrap_schema_type(xmlSchemaTypePtr xtype); 7 | void rxml_init_schema_type(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-2: -------------------------------------------------------------------------------- 1 | 2 | 3 | A B 4 | 5 | A 6 | 7 | B 8 | A B 9 | C 10 | 11 | -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-2: -------------------------------------------------------------------------------- 1 | 2 | 3 | A B 4 | 5 | A 6 | 7 | B 8 | A B 9 | C 10 | 11 | -------------------------------------------------------------------------------- /test/model/xinclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |

This libxml2 binding has the following project information: 4 |

5 |
-------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-2: -------------------------------------------------------------------------------- 1 | 2 | 3 | A B 4 | 5 | A 6 | 7 | B 8 | A B 9 | C 10 | 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_namespaces.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_NAMESPACES__ 4 | #define __RXML_NAMESPACES__ 5 | 6 | extern VALUE cXMLNamespaces; 7 | 8 | void rxml_init_namespaces(void); 9 | #endif 10 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RUBY_XML_H__ 4 | #define __RUBY_XML_H__ 5 | 6 | extern VALUE mXML; 7 | int rxml_libxml_default_options(); 8 | void rxml_init_xml(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_sax_parser.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_SAX_PARSER__ 4 | #define __RXML_SAX_PARSER__ 5 | 6 | extern VALUE cXMLSaxParser; 7 | 8 | void rxml_init_sax_parser(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_html_parser.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_HTML_PARSER__ 4 | #define __RXML_HTML_PARSER__ 5 | 6 | extern VALUE cXMLHtmlParser; 7 | 8 | void rxml_init_html_parser(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xpath_context.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_XPATH_CONTEXT__ 4 | #define __RXML_XPATH_CONTEXT__ 5 | 6 | extern VALUE cXMLXPathContext; 7 | void rxml_init_xpath_context(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /test/model/bands.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | An American heavy metal band formed in Los Angeles, California in 1981. 4 | British heavy metal band formed in 1975. 5 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_parser_context.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_PARSER_CONTEXT__ 4 | #define __RXML_PARSER_CONTEXT__ 5 | 6 | extern VALUE cXMLParserContext; 7 | 8 | void rxml_init_parser_context(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_sax2_handler.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_SAX2_HANDLER__ 4 | #define __RXML_SAX2_HANDLER__ 5 | 6 | extern xmlSAXHandler rxml_sax_handler; 7 | 8 | void rxml_init_sax2_handler(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_parser.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_PARSER__ 4 | #define __RXML_PARSER__ 5 | 6 | #define MAX_LIBXML_FEATURES_LEN 50 7 | 8 | extern VALUE cXMLParser; 9 | 10 | void rxml_init_parser(); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /lib/libxml/attributes.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Attributes 6 | def to_h 7 | inject({}) do |hash, attr| 8 | hash[attr.name] = attr.value 9 | hash 10 | end 11 | end 12 | end 13 | end 14 | end -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xinclude.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_XINCLUDE__ 4 | #define __RXML_XINCLUDE__ 5 | 6 | extern VALUE cXMLXInclude; 7 | extern VALUE eXMLXIncludeError; 8 | 9 | void rxml_init_xinclude(void); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xpath_expression.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_XPATH_EXPRESSION__ 4 | #define __RXML_XPATH_EXPRESSION__ 5 | 6 | extern VALUE cXMLXPathExpression; 7 | 8 | void rxml_init_xpath_expression(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_namespace.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_NAMESPACE__ 4 | #define __RXML_NAMESPACE__ 5 | 6 | extern VALUE cXMLNamespace; 7 | 8 | void rxml_init_namespace(void); 9 | VALUE rxml_namespace_wrap(xmlNsPtr xns); 10 | #endif 11 | -------------------------------------------------------------------------------- /test/c14n/given/example-1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | Hello, world! 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_html_parser_context.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_HTML_PARSER_CONTEXT__ 4 | #define __RXML_HTML_PARSER_CONTEXT__ 5 | 6 | extern VALUE cXMLHtmlParserContext; 7 | 8 | void rxml_init_html_parser_context(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_html_parser_options.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_HTML_PARSER_OPTIONS__ 4 | #define __RXML_HTML_PARSER_OPTIONS__ 5 | 6 | extern VALUE mXMLHtmlParserOptions; 7 | 8 | void rxml_init_html_parser_options(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /test/c14n/given/example-7.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | ]> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/c14n/given/example-8.xpath: -------------------------------------------------------------------------------- 1 | 2 | (//.|//@*|//namespace::*) 3 | [ 4 | self::ietf:e1 5 | or 6 | (parent::ietf:e1 and not(self::text() or self::e2)) 7 | or 8 | count(id("E3")|ancestor-or-self::node()) = count(ancestor-or-self::node()) 9 | ] 10 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_node.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_NODE__ 4 | #define __RXML_NODE__ 5 | 6 | extern VALUE cXMLNode; 7 | 8 | void rxml_init_node(void); 9 | void rxml_node_mark(xmlNodePtr xnode); 10 | VALUE rxml_node_wrap(xmlNodePtr xnode); 11 | #endif 12 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xpointer.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_XPOINTER__ 4 | #define __RXML_XPOINTER__ 5 | 6 | extern VALUE cXMLXPointer; 7 | 8 | void rxml_init_xpointer(void); 9 | VALUE rxml_xpointer_point2(VALUE node, VALUE xptr_str); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /test/model/bands.utf-8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Mötley Crüe is an American heavy metal band formed in Los Angeles, California in 1981. 4 | Iron Maiden is a British heavy metal band formed in 1975. 5 | -------------------------------------------------------------------------------- /website/_layouts/post.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: base 3 | --- 4 |
5 | {% include header.html %} 6 |
7 |
8 | {{ content }} 9 |
10 | 13 | 16 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_document.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_DOCUMENT__ 4 | #define __RXML_DOCUMENT__ 5 | 6 | extern VALUE cXMLDocument; 7 | void rxml_init_document(); 8 | VALUE rxml_document_wrap(xmlDocPtr xnode); 9 | 10 | typedef xmlChar * xmlCharPtr; 11 | #endif 12 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_error.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_ERROR__ 4 | #define __RXML_ERROR__ 5 | 6 | extern VALUE eXMLError; 7 | 8 | void rxml_init_error(); 9 | VALUE rxml_error_wrap(xmlErrorPtr xerror); 10 | void rxml_raise(xmlErrorPtr xerror); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_parser_options.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_PARSER_OPTIONS__ 4 | #define __RXML_PARSER_OPTIONS__ 5 | 6 | #define MAX_LIBXML_FEATURES_LEN 50 7 | 8 | extern VALUE mXMLParserOptions; 9 | 10 | void rxml_init_parser_options(); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_io.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_IO__ 4 | #define __RXML_IO__ 5 | 6 | int rxml_read_callback(void *context, char *buffer, int len); 7 | int rxml_write_callback(void *context, const char *buffer, int len); 8 | void rxml_init_io(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /lib/libxml/schema/attribute.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Schema::Attribute 6 | REQUIRED = 1 7 | OPTIONAL = 2 8 | 9 | def default 10 | node['default'] 11 | end 12 | 13 | def required? 14 | occurs == REQUIRED 15 | end 16 | 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_attr_decl.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_ATTR_DECL__ 4 | #define __RXML_ATTR_DECL__ 5 | 6 | extern VALUE cXMLAttrDecl; 7 | 8 | void rxml_init_attr_decl(void); 9 | VALUE rxml_attr_decl_wrap(xmlAttributePtr xattribute); 10 | VALUE rxml_attr_decl_value_get(VALUE self); 11 | #endif 12 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xpath.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_XPATH__ 4 | #define __RXML_XPATH__ 5 | 6 | extern VALUE mXPath; 7 | 8 | void rxml_init_xpath(void); 9 | 10 | VALUE rxml_xpath_to_value(xmlXPathContextPtr, xmlXPathObjectPtr); 11 | xmlXPathObjectPtr rxml_xpath_from_value(VALUE); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/libxml/xpath_object.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | module XPath 6 | class Object 7 | alias :size :length 8 | 9 | def set 10 | warn("XPath::Object#set is deprecated. Simply use the XPath::Object API instead") 11 | self 12 | end 13 | end 14 | end 15 | end 16 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg 2 | nbproject 3 | web/_site 4 | *.swp 5 | *.swo 6 | 7 | /ext/vc/libxml_ruby.sdf 8 | /ext/vc/libxml_ruby_19/Debug 9 | /ext/vc/libxml_ruby_18/Debug 10 | /doc 11 | /tmp 12 | /.idea 13 | /ext/vc/ipch 14 | /ext/vc/libxml_ruby.opensdf 15 | .config 16 | InstalledFiles 17 | ext/libxml/libxml_ruby.bundle 18 | libxml-ruby.xcodeproj/ 19 | .DS_Store 20 | /ext/vc/*.suo 21 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_attr.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_ATTR__ 4 | #define __RXML_ATTR__ 5 | 6 | extern VALUE cXMLAttr; 7 | 8 | void rxml_init_attr(void); 9 | VALUE rxml_attr_wrap(xmlAttrPtr xattr); 10 | VALUE rxml_attr_value_get(VALUE self); 11 | VALUE rxml_attr_value_set(VALUE self, VALUE val); 12 | #endif 13 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_schema_facet.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_SCHEMA_FACET__ 2 | #define __RXML_SCHEMA_FACET__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | extern VALUE cXMLSchemaFacet; 9 | 10 | VALUE rxml_wrap_schema_facet(xmlSchemaFacetPtr facet); 11 | void rxml_init_schema_facet(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /test/c14n/given/example-8.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | ]> 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/c14n/given/example-5.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | ]> 8 | 9 | &ent1;, &ent2;! 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xinclude.c: -------------------------------------------------------------------------------- 1 | #include "ruby_libxml.h" 2 | #include "ruby_xml_xinclude.h" 3 | 4 | VALUE cXMLXInclude; 5 | 6 | /* 7 | * Document-class: LibXML::XML::XInclude 8 | * 9 | * The ruby bindings do not currently expose libxml's 10 | * XInclude fuctionality. 11 | */ 12 | 13 | void rxml_init_xinclude(void) 14 | { 15 | cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject); 16 | } 17 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_schema_element.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_SCHEMA_ELEMENT__ 2 | #define __RXML_SCHEMA_ELEMENT__ 3 | 4 | #include "ruby_xml_schema.h" 5 | #include 6 | #include 7 | #include 8 | 9 | extern VALUE cXMLSchemaElement; 10 | 11 | VALUE rxml_wrap_schema_element(xmlSchemaElementPtr xelement); 12 | void rxml_init_schema_element(void); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_xpath_object.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_XPATH_OBJECT__ 2 | #define __RXML_XPATH_OBJECT__ 3 | 4 | extern VALUE cXMLXPathObject; 5 | 6 | typedef struct rxml_xpath_object 7 | { 8 | xmlDocPtr xdoc; 9 | xmlXPathObjectPtr xpop; 10 | VALUE nsnodes; 11 | } rxml_xpath_object; 12 | 13 | 14 | void rxml_init_xpath_object(void); 15 | VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # To make testing/debugging easier, test within this source tree versus an installed gem 4 | 5 | dir = File.dirname(__FILE__) 6 | root = File.expand_path(File.join(dir, '..')) 7 | lib = File.expand_path(File.join(root, 'lib')) 8 | ext = File.expand_path(File.join(root, 'ext', 'libxml')) 9 | 10 | $LOAD_PATH << lib 11 | $LOAD_PATH << ext 12 | 13 | require 'xml' 14 | 15 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-4: -------------------------------------------------------------------------------- 1 | 2 | First line 3 | Second line 4 | 2 5 | value>"0" && value<"10" ?"valid":"error" 6 | valid 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-4: -------------------------------------------------------------------------------- 1 | 2 | First line 3 | Second line 4 | 2 5 | value>"0" && value<"10" ?"valid":"error" 6 | valid 7 | 8 | 9 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_input_cbg.h: -------------------------------------------------------------------------------- 1 | #ifndef _INPUT_CBG_ 2 | #define _INPUT_CBG_ 3 | 4 | void rxml_init_input_callbacks(void); 5 | 6 | typedef struct ic_doc_context { 7 | char *buffer; 8 | char *bpos; 9 | int remaining; 10 | } ic_doc_context; 11 | 12 | typedef struct ic_scheme { 13 | char *scheme_name; 14 | VALUE class; 15 | int name_len; 16 | 17 | struct ic_scheme *next_scheme; 18 | } ic_scheme; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-4: -------------------------------------------------------------------------------- 1 | 2 | First line 3 | Second line 4 | 2 5 | value>"0" && value<"10" ?"valid":"error" 6 | valid 7 | 8 | 9 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_schema_attribute.h: -------------------------------------------------------------------------------- 1 | #ifndef __RXML_SCHEMA_ATTRIBUTE__ 2 | #define __RXML_SCHEMA_ATTRIBUTE__ 3 | 4 | #include "ruby_xml_schema.h" 5 | #include 6 | #include 7 | #include 8 | 9 | extern VALUE cXMLSchemaAttribute; 10 | 11 | 12 | void rxml_init_schema_attribute(void); 13 | VALUE rxml_wrap_schema_attribute(xmlSchemaAttributeUsePtr attr); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_version.h: -------------------------------------------------------------------------------- 1 | /* Don't nuke this block! It is used for automatically updating the 2 | * versions below. VERSION = string formatting, VERNUM = numbered 3 | * version for inline testing: increment both or none at all.*/ 4 | #define RUBY_LIBXML_VERSION "2.6.0" 5 | #define RUBY_LIBXML_VERNUM 260 6 | #define RUBY_LIBXML_VER_MAJ 2 7 | #define RUBY_LIBXML_VER_MIN 6 8 | #define RUBY_LIBXML_VER_MIC 0 9 | #define RUBY_LIBXML_VER_PATCH 0 10 | -------------------------------------------------------------------------------- /test/tc_deprecated_require.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require 'xml/libxml' 4 | require 'test/unit' 5 | 6 | class TestDeprecatedRequire < Test::Unit::TestCase 7 | def test_basic 8 | xp = XML::Parser.string('onetwo') 9 | assert_instance_of(XML::Parser, xp) 10 | @doc = xp.parse 11 | assert_instance_of(XML::Document, @doc) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/c14n/given/example-4.xml: -------------------------------------------------------------------------------- 1 | ]> 2 | 3 | First line Second line 4 | 2 5 | "0" && value<"10" ?"valid":"error"]]> 6 | valid 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/model/atom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <![CDATA[<<strong>>]]> 7 | 8 | 9 | hi there 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_attributes.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_ATTRIBUTES__ 4 | #define __RXML_ATTRIBUTES__ 5 | 6 | extern VALUE cXMLAttributesibutes; 7 | 8 | void rxml_init_attributes(void); 9 | VALUE rxml_attributes_new(xmlNodePtr xnode); 10 | 11 | VALUE rxml_attributes_attribute_get(VALUE self, VALUE name); 12 | VALUE rxml_attributes_attribute_set(VALUE self, VALUE name, VALUE value); 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /test/ets_doc_file.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | # This is related to bug 8337, complaint is on amd64/fbsd 6 | # unknown if it happens on other amd64/os combos 7 | 8 | Process.setrlimit(Process::RLIMIT_NOFILE,10005) 9 | 10 | (1..10000).each{|time| 11 | XML::Document.file(File.join(File.dirname(__FILE__),'ets_test.xml')) 12 | if time % 100 == 0 13 | print "\r#{time}" 14 | $stdout.flush 15 | end 16 | } 17 | puts "\n" 18 | -------------------------------------------------------------------------------- /test/etc_doc_to_s.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | 1.times do |count| 6 | 7 | xml_doc = XML::Document.new() 8 | xml_doc.encoding = "UTF-8" 9 | xml_doc.root = XML::Node.new("Request") 10 | 11 | 1000.times do |index| 12 | xml_doc.root << node = XML::Node.new("row") 13 | node["user_id"] = index.to_s 14 | node << "600445" 15 | end 16 | 17 | xml_str = xml_doc.to_s 18 | print "\r#{count}" 19 | $stdout.flush 20 | end 21 | puts "\n" 22 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_reader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2006 Apple Computer Inc. 2 | * Please see the LICENSE file for copyright and distribution information. */ 3 | 4 | #ifndef __RXML_READER__ 5 | #define __RXML_READER__ 6 | 7 | #include 8 | #include 9 | 10 | extern VALUE cXMLReader; 11 | 12 | void rxml_init_reader(void); 13 | 14 | /* Exported to be used by XML::Document#reader */ 15 | VALUE rxml_reader_new_walker(VALUE self, VALUE doc); 16 | 17 | #endif /* __rxml_READER__ */ 18 | -------------------------------------------------------------------------------- /lib/xml.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # This file loads libxml and adds the LibXML namespace 4 | # to the toplevel for conveneience. The end result 5 | # is to have XML:: universally exposed. 6 | # 7 | # It is recommend that you only load this file for libs 8 | # that do not have their own namespace, eg. administrative 9 | # scripts, personal programs, etc. For other applications 10 | # require 'libxml' instead and include LibXML into your 11 | # app/libs namespace. 12 | 13 | require 'libxml' 14 | include LibXML -------------------------------------------------------------------------------- /test/ets_doc_to_s.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | 100.times do |count| 6 | 7 | xml_doc = XML::Document.new() 8 | xml_doc.encoding = "UTF-8" 9 | xml_doc.root = XML::Node.new("Request") 10 | 11 | 1000.times do |index| 12 | 13 | xml_doc.root << node = XML::Node.new("row") 14 | node["user_id"] = index.to_s 15 | node << "600445" 16 | 17 | end 18 | 19 | xml_str = xml_doc.to_s 20 | print "\r#{count}" 21 | $stdout.flush 22 | end 23 | puts "\n" 24 | -------------------------------------------------------------------------------- /test/ets_node_gc.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | # test of bug 13310, clears MEM2 6 | 7 | include GC 8 | 9 | inner = XML::Node.new('inner') 10 | save = nil 11 | 1.times do 12 | outer = XML::Node.new('outer') 13 | outer.child = inner 14 | 1.times do 15 | doc = XML::Document.new 16 | doc.root = outer 17 | # Uncomment the following line and it won't crash 18 | save = doc 19 | end 20 | garbage_collect 21 | end 22 | garbage_collect 23 | puts inner 24 | -------------------------------------------------------------------------------- /test/c14n/result/with-comments/example-3: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/c14n/result/without-comments/example-3: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/c14n/result/1-1-without-comments/example-3: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /website/_includes/sidebar.html: -------------------------------------------------------------------------------- 1 | Navigation
2 | 11 | -------------------------------------------------------------------------------- /lib/libxml/properties.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Node 6 | def property(name) 7 | warn('Node#properties is deprecated. Use Node#[] instead.') 8 | self[name] 9 | end 10 | 11 | def properties 12 | warn('Node#properties is deprecated. Use Node#attributes instead.') 13 | self.attributes 14 | end 15 | 16 | def properties? 17 | warn('Node#properties? is deprecated. Use Node#attributes? instead.') 18 | self.attributes? 19 | end 20 | end 21 | 22 | end 23 | end -------------------------------------------------------------------------------- /lib/libxml/schema/element.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Schema::Element 6 | def required? 7 | !min_occurs.zero? 8 | end 9 | 10 | def array? 11 | max_occurs > 1 12 | end 13 | 14 | def elements 15 | type.elements 16 | end 17 | 18 | def annotation 19 | return if node.nil? 20 | annotations = node.children.select { |n| n.name == 'annotation' } 21 | annotations.map do |annotation| 22 | annotation.children.map(&:content).join("\n") 23 | end.join("\n") 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/libxml/ns.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class NS < Namespace # :nodoc: 6 | def initialize(node, prefix, href) 7 | warn('The XML::NS class is deprecated. Use XML::Namespace instead.') 8 | super(node, href, prefix) 9 | end 10 | 11 | def href? 12 | warn('XML::NS#href? is deprecated. Use !XML::NS#href.nil? instead.') 13 | not self.href.nil? 14 | end 15 | 16 | def prefix? 17 | warn('XML::NS#prefix? is deprecated. Use !XML::NS#prefix?.nil? instead.') 18 | not self.previx.nil? 19 | end 20 | end 21 | end 22 | end -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_encoding.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RXML_ENCODING__ 4 | #define __RXML_ENCODING__ 5 | 6 | extern VALUE mXMLEncoding; 7 | 8 | void rxml_init_encoding(); 9 | 10 | // Ruby 1.8/1.9 encoding compatibility 11 | VALUE rxml_new_cstr(const char* xstr, const char* xencoding); 12 | VALUE rxml_new_cstr_len(const char* xstr, const int length, const char* xencoding); 13 | 14 | #ifdef HAVE_RUBY_ENCODING_H 15 | rb_encoding* rxml_xml_encoding_to_rb_encoding(VALUE klass, xmlCharEncoding xmlEncoding); 16 | rb_encoding* rxml_figure_encoding(const char* xencoding); 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /test/ets_gpx.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require 'libxml' 4 | 5 | 100.times do 6 | doc = XML::Document.new 7 | doc.encoding = 'UTF-8' 8 | 9 | root = XML::Node.new 'gpx' 10 | root['version'] = '1.0' 11 | root['creator'] = 'OpenStreetMap.org' 12 | root['xmlns'] = "http://www.topografix.com/GPX/1/0/" 13 | 14 | doc.root = root 15 | 16 | track = XML::Node.new 'trk' 17 | doc.root << track 18 | 19 | trkseg = XML::Node.new 'trkseg' 20 | track << trkseg 21 | 22 | 1.upto(1000) do |n| 23 | trkpt = XML::Node.new 'trkpt' 24 | trkpt['lat'] = n.to_s 25 | trkpt['lon'] = n.to_s 26 | trkseg << trkpt 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /website/_layouts/base.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | {{ page.title }} 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | {{ content }} 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /test/c14n/given/example-3.xml: -------------------------------------------------------------------------------- 1 | ]> 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/tc_html_parser_context.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | class TestHtmlParserContext < Test::Unit::TestCase 8 | def test_default_options 9 | context = XML::HTMLParser::Context.new 10 | assert_equal(0, context.options) 11 | end 12 | 13 | def test_no_options 14 | context = XML::HTMLParser::Context.new 15 | context.options = 0 16 | assert_equal(0, context.options) 17 | end 18 | 19 | def test_options 20 | context = XML::HTMLParser::Context.new 21 | context.options = XML::HTMLParser::Options::NOERROR 22 | assert_equal(XML::HTMLParser::Options::NOERROR, context.options) 23 | end 24 | end -------------------------------------------------------------------------------- /test/model/shiporder.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | John Smith 6 | 7 | Ola Nordmann 8 |
Langgt 23
9 | 4000 Stavanger 10 | Norway 11 |
12 | 13 | Empire Burlesque 14 | Special Edition 15 | 1 16 | 10.90 17 | 18 | 19 | Hide your heart 20 | 1 21 | 9.90 22 | 23 |
-------------------------------------------------------------------------------- /test/tc_xinclude.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | require 'test/unit' 5 | 6 | class TestXInclude < Test::Unit::TestCase 7 | def setup 8 | @doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml')) 9 | assert_instance_of(XML::Document, @doc) 10 | end 11 | 12 | def teardown 13 | @doc = nil 14 | end 15 | 16 | def test_ruby_xml_xinclude 17 | assert_equal(1, @doc.xinclude) 18 | assert_equal("\n\n

This libxml2 binding has the following project information:\n This is some text to include in an xml file via XInclude.

\n
\n", 19 | @doc.to_s) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /website/README.markdown: -------------------------------------------------------------------------------- 1 | ## Layouts 2 | * base.html - A very basic layout that just defines boilerplate HTML and leaves the rest to be added as *content*. 3 | * post.html - Extends from base.html by *including* a header, a sidebar, and a footer; and leaves the rest to be added as *content*. 4 | 5 | ## Includes 6 | * header.html - This includes the logo and the title. 7 | * sidebar.html - The contents of the sidebar. 8 | * footer.html - A copyright notice. 9 | 10 | ## Posts 11 | Posts use the post.html layout. Posts use the *none* permalink settings, so that they are referred only by their *title*. 12 | 13 | * index.markdown - The main page. 14 | * installation.markdown - Installation notes. 15 | * license.markdown - Libxml-ruby's license. 16 | 17 | Note: Emphasised words are Jekyll terminology. 18 | -------------------------------------------------------------------------------- /ext/libxml/libxml_ruby.def: -------------------------------------------------------------------------------- 1 | LIBRARY libxml_ruby.so 2 | EXPORTS 3 | Init_libxml_ruby 4 | rxml_document_wrap 5 | rxml_xpath_to_value 6 | rxml_xpath_from_value 7 | 8 | cXMLAttr DATA 9 | cXMLAttrDecl DATA 10 | cXMLAttributes DATA 11 | cXMLDocument DATA 12 | cXMLDtd DATA 13 | cXMLHtmlParser DATA 14 | cXMLHtmlParserContext DATA 15 | cXMLNamespace DATA 16 | cXMLNamespaces DATA 17 | cXMLNode DATA 18 | cXMLParser DATA 19 | cXMLParserContext DATA 20 | cXMLReader DATA 21 | cXMLRelaxNG DATA 22 | cXMLSaxParser DATA 23 | cXMLSchema DATA 24 | cXMLXInclude DATA 25 | cXMLXPathContext DATA 26 | cXMLXPathExpression DATA 27 | cXMLXPathObject DATA 28 | cXMLXPointer DATA 29 | eXMLError DATA 30 | mLibXML DATA 31 | mXML DATA 32 | mXMLEncoding DATA 33 | mXMLHtmlParserOptions DATA 34 | mXMLParserOptions DATA 35 | mXPath DATA 36 | -------------------------------------------------------------------------------- /ext/vc/libxml_ruby_18/libxml_ruby.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | C:\MinGW\local\ruby187\bin\ruby.exe 5 | 6 | 7 | tc_attr.rb -v 8 | 9 | 10 | C:\MinGW\local\src\libxml-ruby\test 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /ext/vc/libxml_ruby_19/libxml_ruby_19.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | C:\MinGW\local\ruby193vc\bin\ruby.exe 5 | 6 | 7 | remove_test.rb 8 | 9 | 10 | C:\MinGW\local\src\libxml-ruby\test 11 | WindowsLocalDebugger 12 | 13 | -------------------------------------------------------------------------------- /lib/libxml/reader.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Reader 6 | def reset_error_handler 7 | warn('reset_error_handler is deprecated. Use Error.reset_handler instead') 8 | Error.reset_handler 9 | end 10 | 11 | def set_error_handler(&block) 12 | warn('set_error_handler is deprecated. Use Error.set_handler instead') 13 | Error.set_handler(&block) 14 | end 15 | 16 | # :enddoc: 17 | 18 | def self.walker(doc) 19 | warn("XML::Reader.walker is deprecated. Use XML::Reader.document instead") 20 | self.document(doc) 21 | end 22 | 23 | def self.data(string, options = nil) 24 | warn("XML::Reader.data is deprecated. Use XML::Reader.string instead") 25 | self.string(string, options) 26 | end 27 | end 28 | end 29 | end -------------------------------------------------------------------------------- /test/tc_node_xlink.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # $Id$ 4 | require './test_helper' 5 | 6 | require 'test/unit' 7 | 8 | class TC_XML_Node_XLink < Test::Unit::TestCase 9 | def setup() 10 | xp = XML::Parser.string('one') 11 | doc = xp.parse 12 | assert_instance_of(XML::Document, doc) 13 | @root = doc.root 14 | assert_instance_of(XML::Node, @root) 15 | end 16 | 17 | def teardown() 18 | @root = nil 19 | end 20 | 21 | def test_xml_node_xlink() 22 | for elem in @root.find('fixnum') 23 | assert_instance_of(XML::Node, elem) 24 | assert_instance_of(TrueClass, elem.xlink?) 25 | assert_equal("simple", elem.xlink_type_name) 26 | assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type) 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/libxml/schema/type.rb: -------------------------------------------------------------------------------- 1 | module LibXML 2 | module XML 3 | class Schema::Type 4 | def kind_name 5 | Schema::Types.constants.find { |k| Schema::Types.const_get(k) == kind } 6 | end 7 | 8 | def annotation 9 | return if node.nil? 10 | annotations = node.children.select { |n| n.name == 'annotation' } 11 | annotations.map do |annotation| 12 | annotation.children.map(&:content).join("\n") 13 | end.join("\n") 14 | end 15 | 16 | def annonymus_subtypes 17 | elements.select { |_, e| e.type.name.nil? } 18 | end 19 | 20 | def annonymus_subtypes_recursively(parent=nil) 21 | annonymus_subtypes.map do |element_name, e| 22 | [{[parent, element_name].compact.join('::') => e.type}, 23 | e.type.annonymus_subtypes_recursively(element_name)] 24 | end.flatten 25 | end 26 | 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/libxml.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Load the C-based binding. 4 | begin 5 | RUBY_VERSION =~ /(\d+.\d+)/ 6 | require "#{$1}/libxml_ruby" 7 | rescue LoadError 8 | require "libxml_ruby" 9 | end 10 | # Load Ruby supporting code. 11 | require 'libxml/error' 12 | require 'libxml/parser' 13 | require 'libxml/document' 14 | require 'libxml/namespaces' 15 | require 'libxml/namespace' 16 | require 'libxml/node' 17 | require 'libxml/ns' 18 | require 'libxml/attributes' 19 | require 'libxml/attr' 20 | require 'libxml/attr_decl' 21 | require 'libxml/tree' 22 | require 'libxml/reader' 23 | require 'libxml/html_parser' 24 | require 'libxml/sax_parser' 25 | require 'libxml/sax_callbacks' 26 | require 'libxml/xpath_object' 27 | 28 | #Schema Interface 29 | require 'libxml/schema' 30 | require 'libxml/schema/type' 31 | require 'libxml/schema/element' 32 | require 'libxml/schema/attribute' 33 | 34 | # Deprecated 35 | require 'libxml/properties' -------------------------------------------------------------------------------- /test/tc_node_comment.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | class NodeCommentTest < Test::Unit::TestCase 8 | def setup 9 | xp = XML::Parser.string('') 10 | @doc = xp.parse 11 | assert_instance_of(XML::Document, @doc) 12 | @root = @doc.root 13 | end 14 | 15 | def test_libxml_node_add_comment_01 16 | @root << XML::Node.new_comment('mycomment') 17 | assert_equal '', 18 | @root.to_s.gsub(/\n\s*/,'') 19 | end 20 | 21 | def test_libxml_node_add_comment_02 22 | @root << XML::Node.new_comment('mycomment') 23 | assert_equal 'comment', 24 | @root.child.node_type_name 25 | end 26 | 27 | def test_libxml_node_add_comment_03 28 | @root << el = XML::Node.new_comment('mycomment') 29 | el << "_this_is_added" 30 | assert_equal '', 31 | @root.to_s.gsub(/\n\s*/,'') 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /test/model/shiporder.rnc: -------------------------------------------------------------------------------- 1 | # 2 | # relax ng schema in compact syntax; this cannot be used within libxml but 3 | # was used to write the schema as compact syntax makes it easier to handle. 4 | # relax ng schema in xml syntax was created using trang. 5 | # 6 | namespace xsi = "http://www.w3.org/2001/XMLSchema-instance" 7 | 8 | start = shiporder 9 | 10 | shiporder = element shiporder { attribute orderid { text }, 11 | attribute xsi:noNamespaceSchemaLocation { text }, 12 | orderperson, shipto, item* } 13 | 14 | orderperson = element orderperson { text } 15 | 16 | shipto = element shipto { name, address, city, country } 17 | 18 | name = element name { text } 19 | address = element address { text } 20 | city = element city { text } 21 | country = element country { text } 22 | 23 | item = element item { title, note?, quantity, price } 24 | 25 | title = element title { text } 26 | note = element note { text } 27 | quantity = element quantity { text } 28 | price = element price { text } 29 | -------------------------------------------------------------------------------- /script/benchmark/throughput: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'rubygems' 4 | require 'hpricot' 5 | require 'xml' 6 | require 'rexml/document' 7 | 8 | ITERATIONS = 3 9 | NESTED_ITERATIONS = 5 10 | 11 | def bm(name, filename, &block) 12 | text = File.open(filename).read 13 | length = text.length / 1024.0 / 1024.0 14 | puts "#{filename}: #{name} (#{(length * 1024).round} kb)" 15 | for j in 0 .. NESTED_ITERATIONS 16 | s = Time.now.to_f 17 | for i in 0 .. ITERATIONS 18 | block.call(text) 19 | end 20 | timer = Time.now.to_f - s 21 | puts "\t#{length * ITERATIONS / timer} MB/s" 22 | end 23 | end 24 | 25 | def bm_suite(filenames) 26 | filenames.each do |filename| 27 | bm("LIBXML THROUGHPUT:", filename) do |text| 28 | XML::Document.file(filename) 29 | end 30 | 31 | bm("HPRICOT THROUGHPUT:", filename) do |text| 32 | Hpricot.XML(text) 33 | end 34 | 35 | bm("REXML THROUGHPUT:", filename) do |text| 36 | REXML::Document.new(text) 37 | end 38 | end 39 | end 40 | 41 | bm_suite("hamlet.xml") 42 | -------------------------------------------------------------------------------- /test/tc_node_pi.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | class NodeCommentTest < Test::Unit::TestCase 8 | def setup 9 | xp = XML::Parser.string('') 10 | @doc = xp.parse 11 | assert_instance_of(XML::Document, @doc) 12 | @root = @doc.root 13 | end 14 | 15 | def test_libxml_node_add_pi_01 16 | @root << XML::Node.new_pi('mypi') 17 | assert_equal '', 18 | @root.to_s.gsub(/\n\s*/,'') 19 | end 20 | 21 | def test_libxml_node_add_pi_02 22 | @root << XML::Node.new_pi('mypi') 23 | assert_equal 'pi', 24 | @root.child.node_type_name 25 | end 26 | 27 | def test_libxml_node_add_pi_03 28 | @root << el = XML::Node.new_pi('mypi') 29 | el << "_this_is_added" 30 | assert_equal '', 31 | @root.to_s.gsub(/\n\s*/,'') 32 | end 33 | 34 | def test_libxml_node_add_pi_04 35 | @root << XML::Node.new_pi('mypi','mycontent') 36 | assert_equal '', 37 | @root.to_s.gsub(/\n\s*/,'') 38 | end 39 | 40 | end 41 | -------------------------------------------------------------------------------- /test/tc_node_copy.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | require 'test/unit' 5 | 6 | # see mailing list archive 7 | # [libxml-devel] Segmentation fault when add the cloned/copied node 8 | # 2007/11/27 20:51 9 | 10 | class TestNodeCopy < Test::Unit::TestCase 11 | def setup 12 | str = <<-STR 13 | 14 |
foo
15 |
bar
16 | 17 | STR 18 | 19 | doc = XML::Parser.string(str).parse 20 | 21 | xpath = "//div" 22 | @div1 = doc.find(xpath).to_a[0] 23 | @div2 = doc.find(xpath).to_a[1] 24 | end 25 | 26 | def test_libxml_node_copy_not_segv 27 | @div2.each do |child| 28 | c = child.copy(false) 29 | @div1 << c 30 | end 31 | assert @div1.to_s =~ /foo/ 32 | end 33 | 34 | def test_libxml_node_clone_not_segv 35 | @div2.each do |child| 36 | c = child.clone 37 | @div1 << c 38 | end 39 | assert @div1.to_s =~ /foo/ 40 | end 41 | 42 | end # TC_XML_Node_Copy 43 | -------------------------------------------------------------------------------- /test/tc_xpath_expression.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | class TestXPathExpression < Test::Unit::TestCase 8 | def setup 9 | xp = XML::Parser.string('onetwo') 10 | @doc = xp.parse 11 | end 12 | 13 | def teardown 14 | @doc = nil 15 | end 16 | 17 | def test_nodes 18 | expr = XML::XPath::Expression.compile('/ruby_array/fixnum') 19 | set = @doc.find(expr) 20 | assert_instance_of(XML::XPath::Object, set) 21 | assert_equal(2, set.size) 22 | end 23 | 24 | def test_find_class 25 | expr = XML::XPath::Expression.new('/ruby_array/fixnum') 26 | set = @doc.find(expr) 27 | assert_instance_of(XML::XPath::Object, set) 28 | assert_equal(2, set.size) 29 | end 30 | 31 | def test_find_invalid 32 | error = assert_raise(TypeError) do 33 | set = @doc.find(999) 34 | end 35 | assert_equal('Argument should be an intance of a String or XPath::Expression', 36 | error.to_s) 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/libxml/tree.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Tree # :nodoc: 6 | ELEMENT_NODE = Node::ELEMENT_NODE 7 | ATTRIBUTE_NODE = Node::ATTRIBUTE_NODE 8 | TEXT_NODE = Node::TEXT_NODE 9 | CDATA_SECTION_NODE = Node::CDATA_SECTION_NODE 10 | ENTITY_REF_NODE = Node::ENTITY_REF_NODE 11 | ENTITY_NODE = Node::ENTITY_NODE 12 | PI_NODE = Node::PI_NODE 13 | COMMENT_NODE = Node::COMMENT_NODE 14 | DOCUMENT_NODE = Node::DOCUMENT_NODE 15 | DOCUMENT_TYPE_NODE = Node::DOCUMENT_TYPE_NODE 16 | DOCUMENT_FRAG_NODE = Node::DOCUMENT_FRAG_NODE 17 | NOTATION_NODE = Node::NOTATION_NODE 18 | HTML_DOCUMENT_NODE = Node::HTML_DOCUMENT_NODE 19 | DTD_NODE = Node::DTD_NODE 20 | ELEMENT_DECL = Node::ELEMENT_DECL 21 | ATTRIBUTE_DECL = Node::ATTRIBUTE_DECL 22 | ENTITY_DECL = Node::ENTITY_DECL 23 | NAMESPACE_DECL = Node::NAMESPACE_DECL 24 | XINCLUDE_START = Node::XINCLUDE_START 25 | XINCLUDE_END = Node::XINCLUDE_END 26 | DOCB_DOCUMENT_NODE = Node::DOCB_DOCUMENT_NODE 27 | end 28 | end 29 | end -------------------------------------------------------------------------------- /test/tc_properties.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | # attributes is deprecated - use attributes instead. 8 | # Tests for backwards compatibility 9 | 10 | class Testattributes < Test::Unit::TestCase 11 | def setup() 12 | xp = XML::Parser.string('onetwo') 13 | @doc = xp.parse 14 | end 15 | 16 | def teardown() 17 | @doc = nil 18 | end 19 | 20 | def test_traversal 21 | attributes = @doc.root.attributes 22 | 23 | assert_instance_of(XML::Attributes, attributes) 24 | attribute = attributes.first 25 | assert_equal('uga', attribute.name) 26 | assert_equal('booga', attribute.value) 27 | 28 | attribute = attribute.next 29 | assert_instance_of(XML::Attr, attribute) 30 | assert_equal('foo', attribute.name) 31 | assert_equal('bar', attribute.value) 32 | end 33 | 34 | def test_no_attributes 35 | attributes = @doc.root.child.attributes 36 | assert_instance_of(XML::Attributes, attributes) 37 | assert_equal(0, attributes.length) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2013 Charlie Savage and contributors 2 | Copyright (c) 2002-2007 Sean Chittenden and contributors 3 | Copyright (c) 2001 Wai-Sun "Squidster" Chia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | 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. -------------------------------------------------------------------------------- /test/model/soap.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 1 12 | man1 13 | 14 | 15 | 16 | 2 17 | man2 18 | 19 | 20 | 21 | 3 22 | man3 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /log/changelog.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Facets Changelog 11 | 12 | 15 | 16 | 17 |
18 |

LibXML ChangeLog

19 | 20 | 21 |
22 |

23 | 27 |
28 | 29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |
40 | 41 |
42 | 43 | -------------------------------------------------------------------------------- /website/_posts/2010-06-29-license.markdown: -------------------------------------------------------------------------------- 1 | --- 2 | layout: post 3 | title: Libxml - License 4 | --- 5 |
 6 |   Copyright (c) 2008-2013 Charlie Savage and contributors
 7 |   Copyright (c) 2002-2007 Sean Chittenden and contributors
 8 |   Copyright (c) 2001 Wai-Sun "Squidster" Chia
 9 | 
10 | Permission is hereby granted, free of charge, to any person obtaining a copy of
11 | this software and associated documentation files (the "Software"), to deal in
12 | the Software without restriction, including without limitation the rights to
13 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 | of the Software, and to permit persons to whom the Software is furnished to do
15 | so, subject to the following conditions:
16 | 
17 | The above copyright notice and this permission notice shall be included in all
18 | copies or substantial portions of the Software.
19 | 
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 | SOFTWARE.
27 | -------------------------------------------------------------------------------- /lib/libxml/namespaces.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Namespaces 6 | # call-seq: 7 | # namespace.default -> XML::Namespace 8 | # 9 | # Returns the default namespace for this node or nil. 10 | # 11 | # Usage: 12 | # doc = XML::Document.string('') 13 | # ns = doc.root.namespaces.default_namespace 14 | # assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/') 15 | def default 16 | find_by_prefix(nil) 17 | end 18 | 19 | # call-seq: 20 | # namespace.default_prefix = "string" 21 | # 22 | # Assigns a name (prefix) to the default namespace. 23 | # This makes it much easier to perform XML::XPath 24 | # searches. 25 | # 26 | # Usage: 27 | # doc = XML::Document.string('') 28 | # doc.root.namespaces.default_prefix = 'soap' 29 | # node = doc.root.find_first('soap:Envelope') 30 | def default_prefix=(prefix) 31 | # Find default prefix 32 | ns = find_by_prefix(nil) 33 | raise(ArgumentError, "No default namespace was found") unless ns 34 | Namespace.new(self.node, prefix, ns.href) 35 | end 36 | end 37 | end 38 | end -------------------------------------------------------------------------------- /test/test_suite.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Change to current directory so relative 4 | # requires work. 5 | dir = File.dirname(__FILE__) 6 | Dir.chdir(dir) 7 | 8 | require './tc_attr' 9 | require './tc_attr_decl' 10 | require './tc_attributes' 11 | require './tc_canonicalize' 12 | require './tc_document' 13 | require './tc_document_write' 14 | require './tc_dtd' 15 | require './tc_error' 16 | require './tc_html_parser' 17 | require './tc_html_parser_context' 18 | require './tc_namespace' 19 | require './tc_namespaces' 20 | require './tc_node' 21 | require './tc_node_cdata' 22 | require './tc_node_comment' 23 | require './tc_node_copy' 24 | require './tc_node_edit' 25 | require './tc_node_pi' 26 | require './tc_node_text' 27 | require './tc_node_write' 28 | require './tc_node_xlink' 29 | require './tc_parser' 30 | require './tc_parser_context' 31 | require './tc_reader' 32 | require './tc_relaxng' 33 | require './tc_sax_parser' 34 | require './tc_schema' 35 | require './tc_traversal' 36 | require './tc_writer' 37 | require './tc_xinclude' 38 | require './tc_xpath' 39 | require './tc_xpath_context' 40 | require './tc_xpath_expression' 41 | require './tc_xpointer' 42 | 43 | 44 | if defined?(Encoding) 45 | require './tc_encoding' 46 | require './tc_encoding_sax' 47 | end 48 | # Compatibility 49 | require './tc_properties' 50 | require './tc_deprecated_require' -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_schema_facet.c: -------------------------------------------------------------------------------- 1 | #include "ruby_libxml.h" 2 | #include "ruby_xml_schema_facet.h" 3 | 4 | VALUE cXMLSchemaFacet; 5 | 6 | static void rxml_schema_facet_free(xmlSchemaFacetPtr xschema_type) 7 | { 8 | xschema_type = NULL; 9 | xmlFree(xschema_type); 10 | } 11 | 12 | /* START FACET*/ 13 | 14 | static VALUE rxml_schema_facet_node(VALUE self) 15 | { 16 | xmlSchemaFacetPtr facet; 17 | 18 | Data_Get_Struct(self, xmlSchemaFacet, facet); 19 | 20 | return rxml_node_wrap(facet->node); 21 | } 22 | 23 | static VALUE rxml_schema_facet_value(VALUE self) 24 | { 25 | xmlSchemaFacetPtr facet; 26 | 27 | Data_Get_Struct(self, xmlSchemaFacet, facet); 28 | 29 | QNIL_OR_STRING(facet->value) 30 | } 31 | 32 | static VALUE rxml_schema_facet_kind(VALUE self) 33 | { 34 | xmlSchemaFacetPtr facet; 35 | 36 | Data_Get_Struct(self, xmlSchemaFacet, facet); 37 | 38 | return INT2NUM(facet->type); 39 | } 40 | 41 | VALUE rxml_wrap_schema_facet(xmlSchemaFacetPtr facet) 42 | { 43 | return Data_Wrap_Struct(cXMLSchemaFacet, NULL, rxml_schema_facet_free, facet); 44 | } 45 | 46 | void rxml_init_schema_facet(void) 47 | { 48 | cXMLSchemaFacet = rb_define_class_under(cXMLSchema, "Facet", rb_cObject); 49 | rb_define_method(cXMLSchemaFacet, "value", rxml_schema_facet_value, 0); 50 | rb_define_method(cXMLSchemaFacet, "node", rxml_schema_facet_node, 0); 51 | rb_define_method(cXMLSchemaFacet, "kind", rxml_schema_facet_kind, 0); 52 | } 53 | -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_io.c: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #include "extconf.h" 4 | #include "ruby_libxml.h" 5 | 6 | static ID READ_METHOD; 7 | #ifndef HAVE_RB_IO_BUFWRITE 8 | static ID WRITE_METHOD; 9 | #endif /* !HAVE_RB_IO_BUFWRITE */ 10 | 11 | /* This method is called by libxml when it wants to read 12 | more data from a stream. We go with the duck typing 13 | solution to support StringIO objects. */ 14 | int rxml_read_callback(void *context, char *buffer, int len) 15 | { 16 | VALUE io = (VALUE) context; 17 | VALUE string = rb_funcall(io, READ_METHOD, 1, INT2NUM(len)); 18 | int size; 19 | 20 | if (string == Qnil) 21 | return 0; 22 | 23 | size = RSTRING_LEN(string); 24 | memcpy(buffer, StringValuePtr(string), size); 25 | 26 | return size; 27 | } 28 | 29 | int rxml_write_callback(void *context, const char *buffer, int len) 30 | { 31 | #ifndef HAVE_RB_IO_BUFWRITE 32 | VALUE io, written, string; 33 | 34 | io = (VALUE) context; 35 | string = rb_str_new(buffer, len); 36 | written = rb_funcall(io, WRITE_METHOD, 1, string); 37 | 38 | return NUM2INT(written); 39 | #else 40 | return rb_io_bufwrite((VALUE) context, buffer, (size_t) len); 41 | #endif /* !HAVE_RB_IO_BUFWRITE */ 42 | } 43 | 44 | void rxml_init_io(void) 45 | { 46 | READ_METHOD = rb_intern("read"); 47 | #ifndef HAVE_RB_IO_BUFWRITE 48 | WRITE_METHOD = rb_intern("write"); 49 | #endif /* !HAVE_RB_IO_BUFWRITE */ 50 | } 51 | -------------------------------------------------------------------------------- /ext/vc/libxml_ruby.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml_ruby", "libxml_ruby_18\libxml_ruby.vcxproj", "{0B65CD1D-EEB9-41AE-93BB-75496E504152}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libxml_ruby_19", "libxml_ruby_19\libxml_ruby_19.vcxproj", "{0E73156F-E619-4FD9-8327-113FE3CC942E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Debug|Win32.Build.0 = Debug|Win32 16 | {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|Win32.ActiveCfg = Release|Win32 17 | {0B65CD1D-EEB9-41AE-93BB-75496E504152}.Release|Win32.Build.0 = Release|Win32 18 | {0E73156F-E619-4FD9-8327-113FE3CC942E}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {0E73156F-E619-4FD9-8327-113FE3CC942E}.Debug|Win32.Build.0 = Debug|Win32 20 | {0E73156F-E619-4FD9-8327-113FE3CC942E}.Release|Win32.ActiveCfg = Release|Win32 21 | {0E73156F-E619-4FD9-8327-113FE3CC942E}.Release|Win32.Build.0 = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /test/tc_node_cdata.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | require 'test/unit' 5 | 6 | class CDataCommentTest < Test::Unit::TestCase 7 | def setup 8 | xp = XML::Parser.string('') 9 | @doc = xp.parse 10 | assert_instance_of(XML::Document, @doc) 11 | @root = @doc.root 12 | end 13 | 14 | def test_node_type 15 | cnode = XML::Node.new_cdata('test cdata') 16 | assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type) 17 | end 18 | 19 | def test_add_cdata 20 | @root << XML::Node.new_cdata('mycdata') 21 | assert_equal '', 22 | @root.to_s.gsub(/\n\s*/,'') 23 | end 24 | 25 | def test_add_cdata_2 26 | @root << XML::Node.new_cdata('mycdata') 27 | assert_equal 'cdata', 28 | @root.child.node_type_name 29 | end 30 | 31 | def test_add_cdata_3 32 | @root << el = XML::Node.new_cdata('mycdata') 33 | el << "_this_is_added" 34 | assert_equal '', 35 | @root.to_s.gsub(/\n\s*/,'') 36 | end 37 | 38 | def test_attributes 39 | cnode = XML::Node.new_cdata('test cdata') 40 | assert_equal(0, cnode.attributes.length) 41 | end 42 | 43 | def test_set_cdata_attribute 44 | cnode = XML::Node.new_cdata('test cdata') 45 | 46 | # Can't create attributes on non-element nodes 47 | assert_raise(ArgumentError) do 48 | cnode['attr'] = '123' 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /lib/libxml/namespace.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class Namespace 6 | include Comparable 7 | include Enumerable 8 | 9 | # call-seq: 10 | # namespace1 <=> namespace2 11 | # 12 | # Compares two namespace objects. Namespace objects are 13 | # considered equal if their prefixes and hrefs are the same. 14 | def <=>(other) 15 | if self.prefix.nil? and other.prefix.nil? 16 | self.href <=> other.href 17 | elsif self.prefix.nil? 18 | -1 19 | elsif other.prefix.nil? 20 | 1 21 | else 22 | self.prefix <=> other.prefix 23 | end 24 | end 25 | 26 | # call-seq: 27 | # namespace.each {|ns| .. } 28 | # 29 | # libxml stores namespaces in memory as a linked list. 30 | # Use the each method to iterate over the list. Note 31 | # the first namespace in the loop is the current namespace. 32 | # 33 | # Usage: 34 | # namespace.each do |ns| 35 | # .. 36 | # end 37 | def each 38 | ns = self 39 | 40 | while ns 41 | yield ns 42 | ns = ns.next 43 | end 44 | end 45 | 46 | # call-seq: 47 | # namespace.to_s -> "string" 48 | # 49 | # Returns the string represenation of a namespace. 50 | # 51 | # Usage: 52 | # namespace.to_s 53 | def to_s 54 | if self.prefix 55 | "#{self.prefix}:#{self.href}" 56 | else 57 | self.href 58 | end 59 | end 60 | end 61 | end 62 | end -------------------------------------------------------------------------------- /test/tc_relaxng.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | class TestRelaxNG < Test::Unit::TestCase 8 | def setup 9 | file = File.join(File.dirname(__FILE__), 'model/shiporder.xml') 10 | @doc = XML::Document.file(file) 11 | end 12 | 13 | def teardown 14 | @doc = nil 15 | end 16 | 17 | def relaxng 18 | document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.rng')) 19 | relaxng = XML::RelaxNG.document(document) 20 | end 21 | 22 | def test_from_doc 23 | assert_instance_of(XML::RelaxNG, relaxng) 24 | end 25 | 26 | def test_valid 27 | assert(@doc.validate_relaxng(relaxng)) 28 | end 29 | 30 | def test_invalid 31 | new_node = XML::Node.new('invalid', 'this will mess up validation') 32 | @doc.root << new_node 33 | 34 | error = assert_raise(XML::Error) do 35 | @doc.validate_relaxng(relaxng) 36 | end 37 | 38 | assert_not_nil(error) 39 | assert_kind_of(XML::Error, error) 40 | assert(error.message.match(/Error: Did not expect element invalid there/)) 41 | assert_equal(XML::Error::RELAXNGV, error.domain) 42 | assert_equal(XML::Error::LT_IN_ATTRIBUTE, error.code) 43 | assert_equal(XML::Error::ERROR, error.level) 44 | assert(error.file.match(/shiporder\.xml/)) 45 | assert_nil(error.line) 46 | assert_equal('invalid', error.str1) 47 | assert_nil(error.str2) 48 | assert_nil(error.str3) 49 | assert_equal(0, error.int1) 50 | assert_equal(0, error.int2) 51 | assert_not_nil(error.node) 52 | assert_equal('invalid', error.node.name) 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /test/model/shiporder.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Shiporder type documentation 8 | 9 | 10 | 11 | 12 | orderperson element documentation 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /test/model/merge_bug_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 59 | -------------------------------------------------------------------------------- /libxml-ruby.gemspec: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | # Determine the current version of the software 4 | version = File.read('ext/libxml/ruby_xml_version.h').match(/\s*RUBY_LIBXML_VERSION\s*['"](\d.+)['"]/)[1] 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'libxml-ruby' 8 | spec.version = version 9 | spec.homepage = 'http://xml4r.github.com/libxml-ruby' 10 | spec.summary = 'Ruby Bindings for LibXML2' 11 | spec.description = <<-EOS 12 | The Libxml-Ruby project provides Ruby language bindings for the GNOME 13 | Libxml2 XML toolkit. It is free software, released under the MIT License. 14 | Libxml-ruby's primary advantage over REXML is performance - if speed 15 | is your need, these are good libraries to consider, as demonstrated 16 | by the informal benchmark below. 17 | EOS 18 | spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden', 19 | 'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage', 20 | 'Ryan Johnson'] 21 | spec.platform = Gem::Platform::RUBY 22 | spec.bindir = "bin" 23 | spec.extensions = ["ext/libxml/extconf.rb"] 24 | spec.files = Dir.glob(['HISTORY', 25 | 'LICENSE', 26 | 'libxml-ruby.gemspec', 27 | 'MANIFEST', 28 | 'Rakefile', 29 | 'README.rdoc', 30 | 'setup.rb', 31 | 'ext/libxml/*.def', 32 | 'ext/libxml/*.h', 33 | 'ext/libxml/*.c', 34 | 'ext/libxml/*.rb', 35 | 'ext/vc/*.sln', 36 | 'ext/vc/*.vcprojx', 37 | 'lib/**/*.rb', 38 | 'script/**/*', 39 | 'test/**/*']) 40 | spec.test_files = Dir.glob("test/tc_*.rb") 41 | spec.required_ruby_version = '>= 1.8.6' 42 | spec.date = DateTime.now 43 | spec.add_development_dependency('hanna_guado') 44 | end 45 | -------------------------------------------------------------------------------- /lib/libxml/sax_parser.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class SaxParser 6 | # call-seq: 7 | # XML::SaxParser.file(path) -> XML::SaxParser 8 | # 9 | # Creates a new parser by parsing the specified file or uri. 10 | def self.file(path) 11 | context = XML::Parser::Context.file(path) 12 | self.new(context) 13 | end 14 | 15 | # call-seq: 16 | # XML::SaxParser.io(io) -> XML::SaxParser 17 | # XML::SaxParser.io(io, :encoding => XML::Encoding::UTF_8) -> XML::SaxParser 18 | # 19 | # Creates a new reader by parsing the specified io object. 20 | # 21 | # Parameters: 22 | # 23 | # encoding - The document encoding, defaults to nil. Valid values 24 | # are the encoding constants defined on XML::Encoding. 25 | def self.io(io, options = {}) 26 | context = XML::Parser::Context.io(io) 27 | context.encoding = options[:encoding] if options[:encoding] 28 | self.new(context) 29 | end 30 | 31 | # call-seq: 32 | # XML::SaxParser.string(string) 33 | # 34 | # Creates a new parser by parsing the specified string. 35 | def self.string(string) 36 | context = XML::Parser::Context.string(string) 37 | self.new(context) 38 | end 39 | 40 | # :enddoc: 41 | 42 | def file=(value) 43 | warn("XML::SaxParser#file is deprecated. Use XML::SaxParser.file instead") 44 | @context = XML::Parser::Context.file(value) 45 | end 46 | 47 | def io=(value) 48 | warn("XML::SaxParser#io is deprecated. Use XML::SaxParser.io instead") 49 | @context = XML::Parser::Context.io(value) 50 | end 51 | 52 | def string=(value) 53 | warn("XML::SaxParser#string is deprecated. Use XML::SaxParser.string instead") 54 | @context = XML::Parser::Context.string(value) 55 | end 56 | end 57 | end 58 | end -------------------------------------------------------------------------------- /ext/libxml/ruby_xml_html_parser_options.c: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #include "ruby_libxml.h" 4 | 5 | /* Document-class: LibXML::XML::HTMLParser::Options 6 | * 7 | * Options to control the operation of the HTMLParser. The easiest 8 | * way to set a parser's options is via the methods 9 | * XML::HTMLParser.file, XML::HTMLParser.io or XML::HTMLParser.string. 10 | * For additional control, see XML::HTMLParser::Context#options=. 11 | */ 12 | 13 | VALUE mXMLHtmlParserOptions; 14 | 15 | void rxml_init_html_parser_options(void) 16 | { 17 | mXMLHtmlParserOptions = rb_define_module_under(cXMLHtmlParser, "Options"); 18 | 19 | 20 | #if LIBXML_VERSION >= 20621 21 | /* 1: Relax parsing. */ 22 | rb_define_const(mXMLHtmlParserOptions, "RECOVER", INT2NUM(HTML_PARSE_RECOVER)); 23 | #endif 24 | #if LIBXML_VERSION >= 20708 25 | /* 2: Do not default a doctype if not found */ 26 | rb_define_const(mXMLHtmlParserOptions, "NODEFDTD", INT2NUM(HTML_PARSE_NODEFDTD)); 27 | #endif 28 | /* 32: Suppress error reports. */ 29 | rb_define_const(mXMLHtmlParserOptions, "NOERROR", INT2NUM(HTML_PARSE_NOERROR)); 30 | /* 64: Suppress warning reports. */ 31 | rb_define_const(mXMLHtmlParserOptions, "NOWARNING", INT2NUM(HTML_PARSE_NOWARNING)); 32 | /* 128: Enable pedantic error reporting. */ 33 | rb_define_const(mXMLHtmlParserOptions, "PEDANTIC", INT2NUM(HTML_PARSE_PEDANTIC)); 34 | /* 256: Remove blank nodes. */ 35 | rb_define_const(mXMLHtmlParserOptions, "NOBLANKS", INT2NUM(HTML_PARSE_NOBLANKS)); 36 | #if LIBXML_VERSION >= 20621 37 | /* 2048: Forbid network access. */ 38 | rb_define_const(mXMLHtmlParserOptions, "NONET", INT2NUM(HTML_PARSE_NONET)); 39 | /* 65536: Compact small text nodes. */ 40 | rb_define_const(mXMLHtmlParserOptions, "COMPACT", INT2NUM(HTML_PARSE_COMPACT)); 41 | #endif 42 | #if LIBXML_VERSION >= 20707 43 | /* 8192: Do not add implied html/body... elements */ 44 | rb_define_const(mXMLHtmlParserOptions, "NOIMPLIED", INT2NUM(HTML_PARSE_NOIMPLIED)); 45 | #endif 46 | } 47 | -------------------------------------------------------------------------------- /test/tc_namespace.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | 5 | require 'test/unit' 6 | 7 | class TestNS < Test::Unit::TestCase 8 | def setup 9 | file = File.join(File.dirname(__FILE__), 'model/soap.xml') 10 | @doc = XML::Document.file(file) 11 | end 12 | 13 | def teardown 14 | @doc = nil 15 | end 16 | 17 | def test_create_ns 18 | node = XML::Node.new('foo') 19 | ns = XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com') 20 | assert_equal(ns.prefix, 'my_namepace') 21 | assert_equal(ns.href, 'http://www.mynamespace.com') 22 | end 23 | 24 | def test_create_default_ns 25 | node = XML::Node.new('foo') 26 | ns = XML::Namespace.new(node, nil, 'http://www.mynamespace.com') 27 | assert_equal(ns.prefix, nil) 28 | assert_equal(ns.href, 'http://www.mynamespace.com') 29 | end 30 | 31 | def test_create_unbound_ns 32 | error = assert_raise(TypeError) do 33 | XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com') 34 | end 35 | assert_equal('wrong argument type nil (expected Data)', error.to_s) 36 | end 37 | 38 | def test_duplicate_ns 39 | node = XML::Node.new('foo') 40 | XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') 41 | assert_raises(XML::Error) do 42 | XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com') 43 | end 44 | end 45 | 46 | def test_eql 47 | node = XML::Node.new('Envelope') 48 | ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') 49 | 50 | assert(node.namespaces.namespace.eql?(node.namespaces.namespace)) 51 | end 52 | 53 | def test_equal 54 | node1 = XML::Node.new('Envelope') 55 | ns1 = XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') 56 | 57 | node2 = XML::Node.new('Envelope') 58 | ns2 = XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/') 59 | 60 | assert(ns1 == ns2) 61 | end 62 | end -------------------------------------------------------------------------------- /ext/libxml/libxml.c: -------------------------------------------------------------------------------- 1 | #include "ruby_libxml.h" 2 | 3 | #if RUBY_INTERN_H 4 | #include 5 | #else 6 | #include 7 | #endif 8 | 9 | 10 | VALUE mLibXML; 11 | 12 | static void rxml_init_memory(void) 13 | { 14 | /* Disable for now - broke attributes. 15 | xmlGcMemSetup( 16 | (xmlFreeFunc)ruby_xfree, 17 | (xmlMallocFunc)ruby_xmalloc, 18 | (xmlMallocFunc)ruby_xmalloc, 19 | (xmlReallocFunc)ruby_xrealloc, 20 | (xmlStrdupFunc)ruby_strdup 21 | );*/ 22 | } 23 | 24 | void Init_libxml_ruby(void) 25 | { 26 | /* The libxml gem provides Ruby language bindings for GNOME's Libxml2 27 | * XML toolkit. To get started you may: 28 | * 29 | * require 'test_helper' 30 | * document = XML::Document.new 31 | * 32 | * However, when creating an application or library you plan to 33 | * redistribute, it is best to not add the LibXML module to the global 34 | * namespace, in which case you can either write your code like this: 35 | * 36 | * require 'libxml' 37 | * document = LibXML::XML::Document.new 38 | * 39 | * Refer to the README file to get started and the LICENSE file for 40 | * copyright and distribution information. 41 | */ 42 | mLibXML = rb_define_module("LibXML"); 43 | 44 | rxml_init_memory(); 45 | rxml_init_xml(); 46 | rxml_init_io(); 47 | rxml_init_error(); 48 | rxml_init_encoding(); 49 | rxml_init_parser(); 50 | rxml_init_parser_context(); 51 | rxml_init_parser_options(); 52 | rxml_init_node(); 53 | rxml_init_attributes(); 54 | rxml_init_attr(); 55 | rxml_init_attr_decl(); 56 | rxml_init_document(); 57 | rxml_init_namespaces(); 58 | rxml_init_namespace(); 59 | rxml_init_sax_parser(); 60 | rxml_init_sax2_handler(); 61 | rxml_init_xinclude(); 62 | rxml_init_xpath(); 63 | rxml_init_xpath_object(); 64 | rxml_init_xpath_context(); 65 | rxml_init_xpath_expression(); 66 | rxml_init_xpointer(); 67 | rxml_init_html_parser(); 68 | rxml_init_html_parser_options(); 69 | rxml_init_html_parser_context(); 70 | rxml_init_input_callbacks(); 71 | rxml_init_dtd(); 72 | rxml_init_schema(); 73 | rxml_init_relaxng(); 74 | rxml_init_reader(); 75 | rxml_init_writer(); 76 | } 77 | -------------------------------------------------------------------------------- /ext/libxml/ruby_libxml.h: -------------------------------------------------------------------------------- 1 | /* Please see the LICENSE file for copyright and distribution information */ 2 | 3 | #ifndef __RUBY_LIBXML_H__ 4 | #define __RUBY_LIBXML_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /* Needed prior to Ruby 1.9.1 */ 20 | #ifndef RHASH_TBL 21 | #define RHASH_TBL(s) (RHASH(s)->tbl) 22 | #endif 23 | 24 | // Encoding support added in Ruby 1.9.* 25 | #ifdef HAVE_RUBY_ENCODING_H 26 | #include 27 | #endif 28 | 29 | #ifdef LIBXML_DEBUG_ENABLED 30 | #include 31 | #endif 32 | #ifdef LIBXML_XINCLUDE_ENABLED 33 | #include 34 | #endif 35 | #ifdef LIBXML_XPTR_ENABLED 36 | #include 37 | #endif 38 | 39 | #include "ruby_xml_version.h" 40 | #include "ruby_xml.h" 41 | #include "ruby_xml_io.h" 42 | #include "ruby_xml_error.h" 43 | #include "ruby_xml_encoding.h" 44 | #include "ruby_xml_attributes.h" 45 | #include "ruby_xml_attr.h" 46 | #include "ruby_xml_attr_decl.h" 47 | #include "ruby_xml_document.h" 48 | #include "ruby_xml_node.h" 49 | #include "ruby_xml_namespace.h" 50 | #include "ruby_xml_namespaces.h" 51 | #include "ruby_xml_parser.h" 52 | #include "ruby_xml_parser_options.h" 53 | #include "ruby_xml_parser_context.h" 54 | #include "ruby_xml_html_parser.h" 55 | #include "ruby_xml_html_parser_options.h" 56 | #include "ruby_xml_html_parser_context.h" 57 | #include "ruby_xml_reader.h" 58 | #include "ruby_xml_writer.h" 59 | #include "ruby_xml_sax2_handler.h" 60 | #include "ruby_xml_sax_parser.h" 61 | #include "ruby_xml_writer.h" 62 | #include "ruby_xml_xinclude.h" 63 | #include "ruby_xml_xpath.h" 64 | #include "ruby_xml_xpath_expression.h" 65 | #include "ruby_xml_xpath_context.h" 66 | #include "ruby_xml_xpath_object.h" 67 | #include "ruby_xml_xpointer.h" 68 | #include "ruby_xml_input_cbg.h" 69 | #include "ruby_xml_dtd.h" 70 | #include "ruby_xml_schema.h" 71 | #include "ruby_xml_relaxng.h" 72 | 73 | extern VALUE mLibXML; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lib/libxml/attr_decl.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | module LibXML 4 | module XML 5 | class AttrDecl 6 | include Enumerable 7 | 8 | # call-seq: 9 | # attr_decl.child -> nil 10 | # 11 | # Obtain this attribute declaration's child attribute(s). 12 | # It will always be nil. 13 | def child 14 | nil 15 | end 16 | 17 | # call-seq: 18 | # attr_decl.child? -> (true|false) 19 | # 20 | # Returns whether this attribute declaration has child attributes. 21 | # 22 | def child? 23 | not self.children.nil? 24 | end 25 | 26 | # call-seq: 27 | # attr_decl.doc? -> (true|false) 28 | # 29 | # Determine whether this attribute declaration is associated with an 30 | # XML::Document. 31 | def doc? 32 | not self.doc.nil? 33 | end 34 | 35 | # call-seq: 36 | # attr_decl.next? -> (true|false) 37 | # 38 | # Determine whether there is a next attribute declaration. 39 | def next? 40 | not self.next.nil? 41 | end 42 | 43 | # call-seq: 44 | # attr_decl.parent? -> (true|false) 45 | # 46 | # Determine whether this attribute declaration has a parent . 47 | def parent? 48 | not self.parent.nil? 49 | end 50 | 51 | # call-seq: 52 | # attr_decl.prev? -> (true|false) 53 | # 54 | # Determine whether there is a previous attribute declaration. 55 | def prev? 56 | not self.prev.nil? 57 | end 58 | 59 | # call-seq: 60 | # attr_decl.node_type_name -> 'attribute declaration' 61 | # 62 | # Returns this attribute declaration's node type name. 63 | def node_type_name 64 | if node_type == Node::ATTRIBUTE_DECL 65 | 'attribute declaration' 66 | else 67 | raise(UnknownType, "Unknown node type: %n", node.node_type); 68 | end 69 | end 70 | 71 | # call-seq: 72 | # attr_decl.to_s -> string 73 | # 74 | # Returns a string representation of this attribute declaration. 75 | def to_s 76 | "#{name} = #{value}" 77 | end 78 | end 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /lib/libxml/hpricot.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | ## Provide hpricot API for libxml. Provided by Michael Guterl, 4 | ## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml 5 | # 6 | #class String 7 | # def to_libxml_doc 8 | # xp = XML::Parser.new 9 | # xp.string = self 10 | # xp.parse 11 | # end 12 | #end 13 | # 14 | #module LibXML 15 | # module XML 16 | # class Document 17 | # alias :search :find 18 | # end 19 | # 20 | # class Node 21 | # # find the child node with the given xpath 22 | # def at(xpath) 23 | # self.find_first(xpath) 24 | # end 25 | # 26 | # # find the array of child nodes matching the given xpath 27 | # def search(xpath) 28 | # results = self.find(xpath).to_a 29 | # if block_given? 30 | # results.each do |result| 31 | # yield result 32 | # end 33 | # end 34 | # return results 35 | # end 36 | # 37 | # def /(xpath) 38 | # search(xpath) 39 | # end 40 | # 41 | # # return the inner contents of this node as a string 42 | # def inner_xml 43 | # child.to_s 44 | # end 45 | # 46 | # # alias for inner_xml 47 | # def inner_html 48 | # inner_xml 49 | # end 50 | # 51 | # # return this node and its contents as an xml string 52 | # def to_xml 53 | # self.to_s 54 | # end 55 | # 56 | # # alias for path 57 | # def xpath 58 | # self.path 59 | # end 60 | # 61 | # def find_with_default_ns(xpath_expr, namespace=nil) 62 | # find_base(xpath_expr, namespace || default_namespaces) 63 | # end 64 | # 65 | # def find_first_with_default_ns(xpath_expr, namespace=nil) 66 | # find_first_base(xpath_expr, namespace || default_namespaces) 67 | # end 68 | # 69 | ## alias_method :find_base, :find unless method_defined?(:find_base) 70 | ## alias_method :find, :find_with_default_ns 71 | ## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base) 72 | ## alias_method :find_first, :find_first_with_default_ns 73 | ## alias :child? :first? 74 | ## alias :children? :first? 75 | ## alias :child :first 76 | # end 77 | # end 78 | #end -------------------------------------------------------------------------------- /test/model/shiporder.rng: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "rubygems" 4 | require "rake/extensiontask" 5 | require "rake/testtask" 6 | require "rubygems/package_task" 7 | require "rdoc/task" 8 | require "yaml" 9 | 10 | GEM_NAME = "libxml-ruby" 11 | SO_NAME = "libxml_ruby" 12 | 13 | # Read the spec file 14 | spec = Gem::Specification.load("#{GEM_NAME}.gemspec") 15 | 16 | # Setup compile tasks 17 | Rake::ExtensionTask.new do |ext| 18 | ext.gem_spec = spec 19 | ext.name = SO_NAME 20 | ext.ext_dir = "ext/libxml" 21 | ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}" 22 | ext.config_options << "--with-xml2-include=C:/MinGW/local/include/libxml2" 23 | ext.config_options << "--with-zlib-dir=C:/MinGW/local" 24 | end 25 | 26 | # Setup generic gem 27 | Gem::PackageTask.new(spec) do |pkg| 28 | pkg.package_dir = 'pkg' 29 | pkg.need_tar = false 30 | end 31 | 32 | # Setup Windows Gem 33 | if RUBY_PLATFORM.match(/win32|mingw32/) 34 | binaries = (FileList['lib/**/*.so', 35 | 'lib/**/*dll']) 36 | 37 | # Windows specification 38 | win_spec = spec.clone 39 | win_spec.platform = Gem::Platform::CURRENT 40 | win_spec.files += binaries.to_a 41 | win_spec.instance_variable_set(:@cache_file, nil) 42 | 43 | # Unset extensions 44 | win_spec.extensions = nil 45 | 46 | # Rake task to build the windows package 47 | Gem::PackageTask.new(win_spec) do |pkg| 48 | pkg.package_dir = 'pkg' 49 | pkg.need_tar = false 50 | end 51 | end 52 | 53 | # RDoc Task 54 | desc "Generate rdoc documentation" 55 | RDoc::Task.new("rdoc") do |rdoc| 56 | rdoc.rdoc_dir = 'website/_site/rdoc' 57 | rdoc.title = "LibXML" 58 | # Show source inline with line numbers 59 | rdoc.options << "--line-numbers" 60 | rdoc.options << "--charset=utf-8" 61 | rdoc.options << "--format=hanna" 62 | # Make the readme file the start page for the generated html 63 | rdoc.main = 'README.rdoc' 64 | rdoc.rdoc_files.include('doc/*.rdoc', 65 | 'ext/**/libxml.c', 66 | 'ext/**/ruby_xml.c', 67 | 'ext/**/*.c', 68 | 'lib/**/*.rb', 69 | 'README.rdoc', 70 | 'HISTORY', 71 | 'LICENSE') 72 | end 73 | 74 | # Test Task 75 | Rake::TestTask.new do |t| 76 | t.libs << "test" 77 | t.verbose = true 78 | end -------------------------------------------------------------------------------- /test/tc_node_text.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require './test_helper' 4 | require 'test/unit' 5 | 6 | class TestTextNode < Test::Unit::TestCase 7 | def test_content 8 | node = XML::Node.new_text('testdata') 9 | assert_instance_of(XML::Node, node) 10 | assert_equal('testdata', node.content) 11 | end 12 | 13 | def test_invalid_content 14 | error = assert_raise(TypeError) do 15 | node = XML::Node.new_text(nil) 16 | end 17 | assert_equal('wrong argument type nil (expected String)', error.to_s) 18 | end 19 | 20 | # We use the same facility that libXSLT does here to disable output escaping. 21 | # This lets you specify that the node's content should be rendered unaltered 22 | # whenever it is being output. This is useful for things like