Skip to content

Instantly share code, notes, and snippets.

@privatezero
Last active August 8, 2018 20:34
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 privatezero/095efe7ea47cce9b1ea1f3a4e94328ed to your computer and use it in GitHub Desktop.
Save privatezero/095efe7ea47cce9b1ea1f3a4e94328ed to your computer and use it in GitHub Desktop.
require 'nokogiri'
filename = ''
doc = Nokogiri.XML(File.open(filename))
ead = doc.at_css "ead"
# Clear EAD attributes
ead.each { |att_name| }.each do |attribute_name|
ead.delete(attribute_name)
end
# Add new EAD attributes
ead['xsi:schemaLocation'] = "urn:isbn:1-931666-22-9 http://www.loc.gov/ead/ead.xsd"
ead['xmlns'] = "urn:isbn:1-931666-22-9"
ead['xmlns:ns2'] = "http://www.w3.org/1999/xlink"
ead['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
doc.internal_subset.remove
File.write(filename,doc.to_xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment