[libxml-devel] Node#inner_xml() with all namespaces declared?

2009-08-19 Thread Tim Olsen
Hello,

I am trying to call Node#inner_xml() and have all namespaces referenced
in the inner xml be spit out as well, so that the returned string can be
parsed again.

For example, take the following xml:

http://www.w3.org/2005/Atom";>
  Phil Bogle's Contacts


I would like to be able to call inner_xml() on the feed node, and get:

http://www.w3.org/2005/Atom";>Phil
Bogle's Contacts

Notice the namespace declaration now on the title node.

I couldn't find an option to pass to inner_xml() (or to_s()) to do this.
 I was thinking maybe I could modify what Namespaces#definitions()
returns but I couldn't find a method to modify the definitions.

Any idea how to achieve this?

Thanks,
Tim
___
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel


Re: [libxml-devel] Node#inner_xml() with all namespaces declared?

2009-08-19 Thread Tim Olsen
I've found a workaround.  If I copy(true) a node, then the required
namespaces will be declared on the node.  Here is a method that does
what I want:

# creates a copy of each child before doing to_s
# so that namespaces are properly declared
def inner_xml_copy node, options = {}
  return (node.map { |n| n.copy(true).to_s options }.join '')
end

Tim

Tim Olsen wrote:
> Hello,
> 
> I am trying to call Node#inner_xml() and have all namespaces referenced
> in the inner xml be spit out as well, so that the returned string can be
> parsed again.
> 
> For example, take the following xml:
> 
> http://www.w3.org/2005/Atom";>
>   Phil Bogle's Contacts
> 
> 
> I would like to be able to call inner_xml() on the feed node, and get:
> 
> http://www.w3.org/2005/Atom";>Phil
> Bogle's Contacts
> 
> Notice the namespace declaration now on the title node.
> 
> I couldn't find an option to pass to inner_xml() (or to_s()) to do this.
>  I was thinking maybe I could modify what Namespaces#definitions()
> returns but I couldn't find a method to modify the definitions.
> 
> Any idea how to achieve this?
> 
> Thanks,
> Tim
> ___
> libxml-devel mailing list
> libxml-devel@rubyforge.org
> http://rubyforge.org/mailman/listinfo/libxml-devel

___
libxml-devel mailing list
libxml-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/libxml-devel