Reputation: 1865
I have this:
<style:style style:name="MYBOLD" style:family="text" style:parent-style-name="Standard">
<style:text-properties style:font-name="Arial" style:font-name-complex="Arial" fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
</style:style>
Note how the attributes have a namespace.
When I parse it like so:
Nokogiri::XML.fragment(xmltext)
It seems to have lost the namespaces for both the tags and the attributes! Is there any way I can preserve those?
Upvotes: 1
Views: 421
Reputation: 37507
Nokogiri is blind to namespaces except (1) those on the root node, and (2) any that you register yourself. Since a fragment by definition has no root node, you'll have to supply namespace information yourself.
I noticed that the constructor to DocumentFragment has an optional Context node, from which it can glean namespace information. Since you have indicated in your comments that you have a document in which you will insert the fragment, as long as the namespaces are properly registered in that document you can probably use it for the context information.
Upvotes: 3