Hi, As part of my xsd -> xml translation thing I've been working on (you may recall my emails of several weeks ago), I've created a "template" xml document (largely using the tree api). The schema I'm working with has some elements that need to be qualified. The template document is just a skeleton of elements with no text values. Here's a cut down example.
<Top:Top xmlns:Top="http://thing.com/Top" xmlns:Qual="http://thing.com/Qual"> <Foo> <Qual:Bar/> <Qual:Splodge/> ... </Foo> <Other> <Things> ... </Things> </Other> </Top:Top> So everything inside <Foo> needs to be a qualified element. No problem, you just need to create the node "Bar" with the necessary namespace which was defined at the root node, Top. If I dump out this document with xmlDocFormatDump I can see the desired result. However, in the process of doing this I discovered that if you assign a copy of the namespace (with same prefix and href) it will instead redefine the namespace locally within each node. <Qual:Bar xmlns:Qual="http://thing.com/Qual" /> That was fine, I just search for the namespace up to the doc root using xmlSearchNsByHref() when I need to create that node and it worked. Problem one solved, however this same issue would come back again. Now, I want to take this template document and populate it with data values. I'm doing this by traversing the node tree of the template document and calling a callback function back into my application to collect the required data. The callback has the option of excluding elements with minOccurs = 0, or duplicating elements with maxOccurs > 1. This is all done in my template -> instance engine. As I traverse the tree I'm using the following: instance_node = xmlDocCopyNode(template_node, instance_doc, 2); So I want to copy properties and namespaces, but not recursive children as I'm performing the recursion myself. Now, the problem is, that while instance_doc has xmlns:Qual="http://thing.com/Qual" defined at this stage, and while template_node has a namespace which matches template_doc's namespace (hence qualified elements dump correctly), this function will make a duplicate COPY of the namespace, not refer to the template_doc's definition of it. This has the effect of redefining the namespace in the output, which is functionally the same, but looks a bit ugly. Should xmlDocCopyNode handle this a bit smarter (imagine what would happen in the recursive case)? Or should I just use: xmlDocCopyNode(template_node, instance_doc, 0); and handle all the namespace (and properties) copies myself, and re-search the instance_doc for each (copied) namespace definition as required? regards, Callum -- Callum Gibson @ home _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
