H
Hans Fugal
str = '<html><body><a href="http://google.com/">Google</a></body></html>'
doc = Document.new(str)
(desired incantation)
doc.to_s desired output:
<html xmlns="http://www.w3.org/1999/xhtml"><body><a
href="http://google.com/">Google</a></body></html>
More specifically in my situation I have a document (RSS) in one namespace
and I want to do something like:
str = '<a href="foo">foo<hr/></a>'
description_el << Document.new(str)
and get something like:
<rss xmlns:xhtml="http://www.w3.org/1999/xhtml">
<item><description>
<xhtml:a href="foo">foo<xhtml:hr/></xhtml:a>
</description></item>
</rss>
or even
<rss>
<item><description>
<a xmlns="http://www.w3.org/1999/xhtml" href="foo">foo<hr/></a>
</description></item>
</rss>
str is user-entered and for the application asking them to write their own
xhtml is fine, but asking them to prepend the xhtml prefix to every
element is silly.
doc.namespace= doesn't work, which is the only thing I can divine as maybe
being a sensible thing to do.
doc = Document.new(str)
(desired incantation)
doc.to_s desired output:
<html xmlns="http://www.w3.org/1999/xhtml"><body><a
href="http://google.com/">Google</a></body></html>
More specifically in my situation I have a document (RSS) in one namespace
and I want to do something like:
str = '<a href="foo">foo<hr/></a>'
description_el << Document.new(str)
and get something like:
<rss xmlns:xhtml="http://www.w3.org/1999/xhtml">
<item><description>
<xhtml:a href="foo">foo<xhtml:hr/></xhtml:a>
</description></item>
</rss>
or even
<rss>
<item><description>
<a xmlns="http://www.w3.org/1999/xhtml" href="foo">foo<hr/></a>
</description></item>
</rss>
str is user-entered and for the application asking them to write their own
xhtml is fine, but asking them to prepend the xhtml prefix to every
element is silly.
doc.namespace= doesn't work, which is the only thing I can divine as maybe
being a sensible thing to do.