Created
September 26, 2012 09:26
-
-
Save msokk/3787007 to your computer and use it in GitHub Desktop.
Nokogiri conundrum
This file contains 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 to_ddoc | |
xmldata = Nokogiri::XML(ddoc_container) | |
xmldata.css('DataFile').each_with_index do |el, i| | |
frag = Nokogiri::XML.fragment(documents[i].datafile(i)) | |
el.replace frag | |
end | |
xmldata.to_xml | |
end |
This file contains 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" encoding="UTF-8"?> | |
<SignedDoc format="DIGIDOC-XML" version="1.3" xmlns="http://www.sk.ee/DigiDoc/v1.3.0#"> | |
<!-- Default namespace exists in Nokogiri::XML object, but it's missing in serialized form --> | |
<DataFile ContentType="EMBEDDED_BASE64" Filename="10.1.1.210.2072.pdf" Id="D0" MimeType="application/pdf" Size="684191"> | |
<!-- BASE64 data truncated --> | |
</DataFile> | |
<!-- Extra metadata here --> | |
</SignedDoc> |
This file contains 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
# This is xmldata in pry before to_xml call | |
=> #(Document:0x3fdeceebf89c { | |
name = "document", | |
children = [ | |
#(Element:0x3fdeceebf7c0 { | |
name = "SignedDoc", | |
namespace = #(Namespace:0x3fdeceebf798 { | |
href = "http://www.sk.ee/DigiDoc/v1.3.0#" | |
}), | |
attributes = [ | |
#(Attr:0x3fdece969fb4 { name = "format", value = "DIGIDOC-XML" }), | |
#(Attr:0x3fdece969fa0 { name = "version", value = "1.3" })], | |
children = [ | |
#(Text "\n"), | |
#(Element:0x3fdecf67ab04 { | |
name = "DataFile", | |
namespace = #(Namespace:0x3fded0e98a60 { | |
href = "http://www.sk.ee/DigiDoc/v1.3.0#" | |
}), | |
attributes = [ | |
#(Attr:0x3fded0e989e8 { | |
name = "ContentType", | |
value = "EMBEDDED_BASE64" | |
}), | |
#(Attr:0x3fded0e989c0 { | |
name = "Filename", | |
value = "10.1.1.210.2072.pdf" | |
}), | |
#(Attr:0x3fded0e989ac { name = "Id", value = "D0" }), | |
#(Attr:0x3fded0e98998 { | |
name = "MimeType", | |
value = "application/pdf" | |
}), | |
#(Attr:0x3fded0e98984 { name = "Size", value = "684191" })], | |
children = [ | |
#(Text "JVBERi0xLjQKJdDUxdgKNiAwIG9iaiA8PAovTGVuZ3RoIDQ2NTIgICAgICAKL0Zp\nbH | |
}), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment