I am using nokogiri
to generate svg pictures. I would like to add the correct xml preamble and svg DTD declaration to get something like:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg>
...
With builder
I could use instruct!
and declare!
but I want to stick with nokogiri
because I use it for other purpose in my project and I want to stay low on requirements. Do you have some ideas ?
Thanks
Following is from a note at the bottom of the Nokogiri::XML::Builder page (maybe added recently), which I think will do the trick:
builder = Nokogiri::XML::Builder.new do |xml|
xml.doc.create_internal_subset(
'html',
"-//W3C//DTD HTML 4.01 Transitional//EN",
"http://www.w3.org/TR/html4/loose.dtd"
)
xml.root do
xml.foo
end
end
puts builder.to_xml
You can now (don't know from which version) use Node#create_internal_subset to create the DTD node. For more info see: http://nokogiri.org/Nokogiri/XML/Builder.html
And scroll down to the "Document Types" section for an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With