Re: [xml] Get sub-document from xmlDocPtr
- From: Daniel Veillard <veillard redhat com>
- To: Andrew Hartley <andrew hartley bcs org uk>
- Cc: xml gnome org
- Subject: Re: [xml] Get sub-document from xmlDocPtr
- Date: Thu, 17 Jul 2008 08:18:40 -0400
On Thu, Jul 17, 2008 at 03:25:20AM -0700, Andrew Hartley wrote:
Andrew Hartley wrote:
Having extracted a sub-document with an XPath expression and now have an
xmlXPathObjectPtr is there a simple way to output the sub-document into a
new xmlDocPtr so that this sub-document can then be saved to disk?
It's ok, I have worked it out:
[code]
xmlDocPtr pXmlSubDoc = pXPathObj->nodesetval->nodeTab[0]->doc;
[/code]
Note that an XPath object could also be a number, a boolean or a string,
so don't blindly do that dereference and check pXPathObj type first, and
then that the pointer is not null, and then that the node set at least has
one node, and that this node is not a namespace (namespace nodes don't have
pointer back to the document).
Basically there is tons of checking missing there, and i would prefer
if other people didn't just cut and past that everywhere...
I think it really makes more sense to keep the document pointer around,
for example it's embedded in the XPath evaluation context. Beware of bad
scoping/API design that happen frequently when you don't have yet a good
vison of the objects manipulated.
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]