Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
require 'rubygems' require 'nokogiri' puts "" puts "SHOULD NOT BE THIS" puts "" record = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.send("OAI-PMH", :"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", :"xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd", :"xmlns" => "http://www.openarchives.org/OAI/2.0/") do xml.responseDate(Time.now.utc) xml.request({ :verb => "GetRecord", :metadataPrefix => "oai_dc" }, 'http://......./') xml.GetRecord do xml.header do xml.identifier end xml.metadata do xml.send("oai_dc:dc", :"xmlns:oai_dc" => "http://www.openarchives.org/OAI/2.0/oai_dc/", :"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", :"xmlns:dc" => "http://purl.org/dc/elements/1.1/", :"xmlns:dcterms" => "http://purl.org/dc/terms/", :"xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd") do end end end end end puts record.to_xml # Gives this output: # # <?xml version="1.0" encoding="UTF-8"?> # <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> # <responseDate>Wed Dec 16 05:03:35 UTC 2009</responseDate> # <request metadataPrefix="oai_dc" verb="GetRecord">http://......./</request> # <GetRecord> # <header> # <identifier/> # </header> # <metadata> # <oai_dc:dc xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"/> # </metadata> # </GetRecord> #</OAI-PMH> puts "" puts "SHOULD BE THIS" puts "" record = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.send("OAI-PMH", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd", "xmlns" => "http://www.openarchives.org/OAI/2.0/") do xml.responseDate(Time.now.utc) xml.request({ :verb => "GetRecord", :metadataPrefix => "oai_dc" }, 'http://......./') xml.GetRecord do xml.header do xml.identifier end xml.metadata do xml.send("oai_dc:dc", "xmlns:oai_dc" => "http://www.openarchives.org/OAI/2.0/oai_dc/", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xmlns:dc" => "http://purl.org/dc/elements/1.1/", "xmlns:dcterms" => "http://purl.org/dc/terms/", "xsi:schemaLocation" => "http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd") do end end end end end puts record.to_xml # Gives this output: # # <?xml version="1.0" encoding="UTF-8"?> #<OAI-PMH xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.openarchives.org/OAI/2.0/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> # <responseDate>Wed Dec 16 05:03:35 UTC 2009</responseDate> # <request metadataPrefix="oai_dc" verb="GetRecord">http://......./</request> # <GetRecord> # <header> # <identifier/> # </header> # <metadata> # <oai_dc:dc xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"/> # </metadata> # </GetRecord> #</OAI-PMH> puts ""
This paste will be private.
From the Design Piracy series on my blog: