moovweb/gokogiri

Parsing Fragments That Have Namespaces

sorin-ionescu opened this issue · 3 comments

I am having trouble parsing a document fragment that contains elements with namespaces. When added to a node as children, the namespaces are removed even though the namespaces are defined in the root element of the document to which I wish to add the fragment.

var fragment []byte = foo.Fragment()
fmt.Println(fragment) // prints name spaced elements
node.Child(fragment)
fmt.Println(node) // the elements are added, but the namespaces are removed.

I have also tried to parse the fragment manually with no success in preserving the namespaces.

I have noticed that you are wrapping the fragment with a root element. Nevertheless, the fragment seems to be parsed in the context of a node or document root, which, in my case, has the namespaces defined.

Thank you.

Hey sorin, could you give an example of an xml fragment that you're trying to parse that exhibits this behavior?

I added a test case

52bf0ac

Wonder if that's what you wanted to do.

I think it's libxml2 at fault here, at least the one that comes with Mac OS X Lion. The latest libxml2 seems to work properly.