This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xml file: | |
| --- | |
| <match> | |
| <id>1053</id> | |
| <name>Южная Африка - Мексика</name> | |
| <start>2010-06-11 18:00:00</start> | |
| <status>finished</status> | |
| <stage>Групповой этап</stage> | |
| <stadium>Соккер Сити</stadium> | |
| <judge>Равшан Ирматов</judge> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def test_auto_closing_tags | |
| reader = Nokogiri::XML::Reader.from_memory(<<-eoxml) | |
| <xml><city>Paris</city><state/></xml> | |
| eoxml | |
| assert_equal [false, false, nil, nil, true, nil], | |
| reader.map{|node| node.empty_element? if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'nokogiri' | |
| md = "<p>hello</p> <h1>goodbye</h1> <p>kiss it</p> <p>hello</p> <h1>goodbye</h1> <p>kiss it</p>" | |
| loop { | |
| frag = Nokogiri::XML::DocumentFragment.new(Nokogiri::XML::Document.new, md) | |
| GC.start | |
| STDERR.putc "." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'nokogiri' | |
| # | |
| # must set the document root node. one line change to original: | |
| # | |
| n = Nokogiri::XML::Node.new('root', Nokogiri::XML::Document.new) | |
| n.document.root = n | |
| n << Nokogiri::XML::Node.new('child', n.document) | |
| n << (c = Nokogiri::XML::Node.new('child', n.document)) | |
| c.default_namespace = 'foo:bar' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0"?> | |
| <root> | |
| <inventory xmlns="http://alicesautosupply.example.com/"> | |
| <tire name="super slick racing tire" /> | |
| <tire name="all weather tire" /> | |
| </inventory> | |
| <inventory xmlns="http://bobsbikes.com"> | |
| <tire name="narrow street tire" /> | |
| <tire name="mountain trail tire" /> | |
| </inventory> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/ruby | |
| require 'rubygems' | |
| require 'twitter' | |
| require 'open-uri' | |
| require 'nokogiri' | |
| TARGET_USER = "aplusk" | |
| TARGET_COUNT = 1_000_000 | |
| URL = "http://twitter.com/#{TARGET_USER}" | |
| ID = '#follower_count' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'nokogiri' | |
| class Nokogiri::XML::Node | |
| def method_missing name, *args, &block | |
| if args.empty? | |
| list = xpath("//#{name}") | |
| elsif args.first.is_a? Hash | |
| hash = args.first | |
| if hash[:css] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| XML Document parsing benchmark | |
| user system total real | |
| hpricot:xml:doc 10.160000 0.950000 11.110000 ( 11.144462) | |
| hpricot2:xml:doc 0.950000 0.000000 0.950000 ( 0.953266) | |
| nokogiri:compat:doc 0.220000 0.020000 0.240000 ( 0.238401) | |
| nokogiri:xml:doc 0.170000 0.030000 0.200000 ( 0.200283) | |
| XML XPath benchmarks (//status/text, //user/name) | |
| user system total real | |
| hpricot:xml:xpath 7.580000 1.150000 8.730000 ( 8.728314) |