Skip to content

Instantly share code, notes, and snippets.

@msokk
Created September 26, 2012 09:26
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 msokk/3787007 to your computer and use it in GitHub Desktop.
Save msokk/3787007 to your computer and use it in GitHub Desktop.
Nokogiri conundrum
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
<?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 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