On Fri, 2009-02-20 at 19:14 +0100, Daniel Veillard wrote:
On Fri, Feb 13, 2009 at 12:23:09PM -0800, Marc Munro wrote:On Sat, 2009-01-31 at 08:12 +0100, Daniel Veillard wrote:On Thu, Jan 29, 2009 at 01:50:52PM -0800, Marc Munro wrote:I am processing a document which contains nested inclusions using xi:include. How can I tell the source file from which a given node was included into the document?Not always possible, for example if you XInclude a text node, well there is little to help. But you can use 2 things: xml:base attribute left by the xinclude process, if you ask for the base at a given included point, you may get the proper URI if there was room left to put the base attribute at the inclusion point (i.e. on an element) the XInclude process also turns the original xi:include element into an XML_XINCLUDE_START node with all attributes left and also add an XML_XINCLUDE_END after the included element(s)I thought I'd try figuring out the URI the hard way and so traversed to the XML_XINCLUDE_START node for the inclusion. I was hoping to find the href attribute saved there but instead find no attributes at all.The XML_XINCLUDE_START node is really the old xi:xinclude node just changed to be of the new type, really all informations should be there, though the attribute reading API may not work because the node type is not XML_ELEMENT_NODE ... check directly the ->properties list.
Daniel, thanks for the response. Using gdb I have confirmed that the XML_XINCLUDE_START for the nested inclusion has no properties (gdb session pasted below). The node for the outermost inclusion does have the expected properties, and does provide the href attribute. The gdb session follows. The breakpoint is set within my exception handler where prev is an XmlNode * pointing to the XML_XINCLUDE_START node. As you will see the first breakpoint, within the inner nested inclusion, yields a node where there are no properties. The second, for the outermost inclusion, shows the expected properties. -----gdb session-------------------------------- (gdb) break src/xmlfile.c:1062 Breakpoint 1 at 0x805f187: file src/xmlfile.c, line 1062. (gdb) run -n params extract Starting program: /home/marc/proj/skit2/skit_test -n params extract [Thread debugging using libthread_db enabled] Running suite(s): Params [New Thread 0xb7683a00 (LWP 8876)] XX: include XX: dump XX: runsql XX: stylesheet XX: (null) ZZZ DEBUG PRIVNAMES: <('C' . 'create') ('T' . 'temporary') ('U' . 'usage') ('X' . 'execute') ('a' . 'insert') ('c' . 'connect') ('d' . 'delete') ('r' . 'select') ('t' . 'trigger') ('w' . 'update') ('x' . 'references')> XX: exception XX: inclusion [Switching to Thread 0xb7683a00 (LWP 8876)] Breakpoint 1, getNodeURI (node=0x9291f88) at src/xmlfile.c:1062 (gdb) p *prev $1 = {_private = 0x0, type = XML_XINCLUDE_START, name = 0x926f3b0 "include", children = 0x0, last = 0x0, parent = 0x9292698, next = 0x9291f88, prev = 0x9291ed8, doc = 0x926f6c8, ns = 0x9289050, content = 0x0, properties = 0x0, nsDef = 0x0, psvi = 0x0, line = 0, extra = 0} (gdb) c Continuing. HERE INCLUDE START XX: runsql XX: let XX: cluster XX: inclusion Breakpoint 1, getNodeURI (node=0x9292c00) at src/xmlfile.c:1062 (gdb) p *prev $2 = {_private = 0x0, type = XML_XINCLUDE_START, name = 0x926f3b0 "include", children = 0x0, last = 0x0, parent = 0x92720e8, next = 0x9292c00, prev = 0x9272be8, doc = 0x926f6c8, ns = 0x926f8a8, content = 0x0, properties = 0x9272d48, nsDef = 0x0, psvi = 0x0, line = 33, extra = 7} (gdb) p nodeAttribute(prev, "href") $3 = (String *) 0x0 (gdb) p node->properties $4 = (struct _xmlAttr *) 0x9297760 (gdb) p *node->properties $5 = {_private = 0x0, type = XML_ATTRIBUTE_NODE, name = 0x926f491 "base", children = 0x9297798, last = 0x9297798, parent = 0x9292c00, next = 0x0, prev = 0x0, doc = 0x926f6c8, ns = 0x9297708, atype = 0, psvi = 0x0} (gdb) p *node->properties->children $6 = {_private = 0x0, type = XML_TEXT_NODE, name = 0xb7ed55d8 "text", children = 0x0, last = 0x0, parent = 0x9297760, next = 0x0, prev = 0x0, doc = 0x926f6c8, ns = 0x0, content = 0x92977d8 "skitfile:extract/cluster.xml", properties = 0x0, nsDef = 0x0, psvi = 0x0, line = 0, extra = 0} (gdb) -----gdb session-------------------------------- Code called from the node at which an exception is raised, to find the XML_XINCLUDE_START element: -----source code-------------------------------- static xmlChar * getNodeURI(xmlNode *node) { xmlNode *prev; xmlChar *contents; xmlChar *name; String *href; while (node) { fprintf(stderr, "XX: %s\n", nodeName(node)); name = nodeName(node); if (name && streq(name, "inclusion")) { prev = node->prev; if (prev->type == XML_XINCLUDE_START) { fprintf(stderr, "HERE\n"); xmlDebugDumpOneNode(stderr, prev, 1); if (href = nodeAttribute(prev, "href")) { printSexp(stderr, "INCLUSION: ", (Object *) href); objectFree((Object *) href, TRUE); } } } node = node->parent; } return NULL; } -----source code-------------------------------- I am happy to try to track this down if you can offer suggestions. FWIW, I don't think this is the result of random memory corruption as valgrind reports no issues. __ Marc
Attachment:
signature.asc
Description: This is a digitally signed message part