Re: [xml] Xpath Question
Alistair Leslie-Hughes wrote: Hi, I have the following XML ?xml version=\1.0\ encoding=\utf-8\?\r\nstringC4TJXQFL/string and using msxml I can do selectSingleNode(string) to select the root node. Is there an xmlXPath or equivalent function? (assume that I cannot change the string parameter) xmlDocPtr doc; ... xpctxt = xmlXPathNewContext(doc); xpobj = xmlXPathEvalExpression(/string, xpctxt); if(xpobj-nodesetval-nodeNr) xmlNodePtr string_root_node = nodeSet-nodeTab[0]; ... (error checks and freeing stuff omitted.) br, Martin ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Xpath question
On Mon, Jun 02, 2008 at 06:20:07PM -0700, Yong Chen (yongche) wrote: Hi, Got a question regarding xpath usage in libxml2. If I have a document doc, which contains some nodes, say n1, n2, n3. Now I have an xpath as: /bookstore/book[1]/title Do we have any api that can evaluate node n1 and tell me that if we were to apply this xpath string to the document, then n1 would be selected (or not). Basically I want to evaluate an xpath on node basis, not the full document basis. The closest is the patter module, but that works only on a subset of XPath http://xmlsoft.org/html/libxml-pattern.html you will have to look at the code in XPath/Schemas to get an idea on how to use it, as there isn't much documentation. Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ [EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/ ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Xpath question
On Wed, 2007-04-25 at 16:32 -0700, Yong Chen (yongche) wrote: Say I have an xml tree: A B C D E [..] Now say I have xpath /A/B, it selects node B. When I return the result, should I return B node only, or I should return B and also its child (D and E)? You return the whole subtree. Assuming you is an XPath implementation. This list is really for the Gnome XML library, which already implements XPath. Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org www.advogato.org ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Xpath question
On Thu, Jan 11, 2007 at 07:05:36PM -0800, Yong Chen (yongche) wrote: Thanks Daniel. I did some tests for xmlSaveTree, it basically prints out the selected nodes and their children. Is there any way to print out the selected nodes and their parents (till root)? To me it makes very little sense to not print the children of a node, so that would mean printing the document, which is already possible. I can certainly do the traversal via node-parent. Just in case you already have some API available (which will trim the non-selected nodes from the original doc and do xmlDocDump(stdout, doc)). No such API, just walk the tree. Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ [EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/ ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Xpath question
On Wed, Jan 10, 2007 at 05:57:37PM -0800, Yong Chen (yongche) wrote: Hi, I plan to use xpath in libxml2 to get a subset of a xmldoc, I know it can be done by calling xmlXPathEvalExpression(), the result is a xmlXPathObjectPtr which has a nodesetval member pointing to selected nodes (of type xmlNodeSetPtr). My question is, after getting the selected nodes, is there any API I can call to dump the selected nodes in xml tree format? There is a convenient API xmlDocDump(stdout, doc) to dump the whole doc in xml tree format, I'm looking for something like xmlDocDumpSubset(doc, selected-nodes) to dump only the selected nodes in the doc. See http://xmlsoft.org/html/libxml-xmlsave.html#xmlSaveTree Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ [EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/ ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml
Re: [xml] Xpath question
Thanks Daniel. I did some tests for xmlSaveTree, it basically prints out the selected nodes and their children. Is there any way to print out the selected nodes and their parents (till root)? I can certainly do the traversal via node-parent. Just in case you already have some API available (which will trim the non-selected nodes from the original doc and do xmlDocDump(stdout, doc)). Thanks, Yong Chen -Original Message- From: Daniel Veillard [mailto:[EMAIL PROTECTED] Sent: Thursday, January 11, 2007 2:07 AM To: Yong Chen (yongche) Cc: xml@gnome.org Subject: Re: [xml] Xpath question On Wed, Jan 10, 2007 at 05:57:37PM -0800, Yong Chen (yongche) wrote: Hi, I plan to use xpath in libxml2 to get a subset of a xmldoc, I know it can be done by calling xmlXPathEvalExpression(), the result is a xmlXPathObjectPtr which has a nodesetval member pointing to selected nodes (of type xmlNodeSetPtr). My question is, after getting the selected nodes, is there any API I can call to dump the selected nodes in xml tree format? There is a convenient API xmlDocDump(stdout, doc) to dump the whole doc in xml tree format, I'm looking for something like xmlDocDumpSubset(doc, selected-nodes) to dump only the selected nodes in the doc. See http://xmlsoft.org/html/libxml-xmlsave.html#xmlSaveTree Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ [EMAIL PROTECTED] | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/ ___ xml mailing list, project page http://xmlsoft.org/ xml@gnome.org http://mail.gnome.org/mailman/listinfo/xml