Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created December 20, 2012 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsutphin/4348552 to your computer and use it in GitHub Desktop.
Save rsutphin/4348552 to your computer and use it in GitHub Desktop.
A demo script for sparklemotion/nokogiri#816
require 'rubygems'
gem 'nokogiri', ENV['NOKOGIRI_VERSION'] || '1.5.6'
require 'nokogiri'
xml = <<-XML
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ncs="http://www.nationalchildrensstudy.gov" xmlns:ncsdoc="http://www.nationalchildrensstudy.gov/doc" xmlns:xlink="http://www.w3.org/TR/WD-xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.nationalchildrensstudy.gov" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:element ncsdoc:pii="P"/>
</xs:schema>
XML
n = Nokogiri::XML(xml)
e = n.root.elements.first
puts " Ruby: #{RUBY_DESCRIPTION}"
puts "Nokogiri: #{Nokogiri::VERSION}"
puts
puts " With prefix: #{e['ncsdoc:pii'].inspect}"
puts "Without prefix: #{e['pii'].inspect}"

MRI:

    Ruby: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
Nokogiri: 1.5.5

   With prefix: nil
Without prefix: "P"
    Ruby: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
Nokogiri: 1.5.6

   With prefix: "P"
Without prefix: nil

JRuby:

    Ruby: jruby 1.7.1 (1.9.3p327) 2012-12-03 30a153b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_29-b11-402-11E2068 [darwin-x86_64]
Nokogiri: 1.5.5

   With prefix: "P"
Without prefix: nil
    Ruby: jruby 1.7.1 (1.9.3p327) 2012-12-03 30a153b on Java HotSpot(TM) 64-Bit Server VM 1.6.0_29-b11-402-11E2068 [darwin-x86_64]
Nokogiri: 1.5.6

   With prefix: "P"
Without prefix: nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment