Consider example xml file..
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle=" http://www.w3.org/2001/12/soap-encoding ">
<soap:Header>
<m:Trans xmlns:m=" http://www.w3schools.com/transaction/" soap:mustUnderstand="1">234</m:Trans>
</soap:Header>
<soap:Body>
<n:GetPrice xmlns:n=" http://www.w3schools.com/prices">
<n:Item>Apples</n:Item>
</n:GetPrice>
</soap:Body>
</soap:Envelope>
Here, I tried your suggestion of using Xpath to return the xmlNodeSetPtr for all child nodes of <soap:Body>. Here is my code..
[CODE]
doc = xmlParseDoc((const xmlChar*)szSoapBody);
xpath_context = xmlXPathNewContext(doc);
xmlXPathRegisterNs(xpath_context, (const xmlChar*)"e", (const xmlChar*)" http://www.w3.org/2003/05/soap-envelope");
res = xmlXPathEvalExpression((const xmlChar*)"/e:Envelope/e:Body | /e:Envelope/e:Body/*", xpath_context);
nodes = res->nodesetval;
xmlC14NDocDumpMemory( doc, nodes, 1, NULL, 0, &doc_txt_ptr);
[/CODE]
I observed 2 issues with this...
1. I need to use xmlXPathRegisterNs function that is declared in xpathInternals.h . Is it valid for the library user to use functions of xpathInternals.h ? Is xpathInternals.h an internal file to be used only by libxml library developers and not library users? Are there some other alternatives?
2. The xpath _expression_ only returns 'Body', and its immediate child ' GetPrice'. What i wanted is all the entire sub-tree of <soap:Body> including children, grand-children, great-gand-children.. and so on.. all the nodes under <soap:Body>. How do I achieve this?
Can you please suggest me an efficient way of solving my problem?
Thank you,
Chetan
On 4/14/06, Chetan Raj <[EMAIL PROTECTED]> wrote:
Hi,
The idea of having xmlNodeSetPtr for all children nodes of a xml subtree, is to pass xmlNodeSetPtr to the Canonical function - xmlC14NDocDumpMemory. Here i want to cannonicalise only the required xml-subtree.
For example .. I want to canonicalise only the <soap:Body> and all its child nodes in the following xml file :
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle=" http://www.w3.org/2001/12/soap-encoding ">
<soap:Header>
<m:Trans xmlns:m=" http://www.w3schools.com/transaction/" soap:mustUnderstand="1">234</m:Trans>
</soap:Header>
<soap:Body>
<n:GetPrice xmlns:n=" http://www.w3schools.com/prices">
<n:Item>Apples</n:Item>
</n:GetPrice>
</soap:Body>
</soap:Envelope>
If what I am trying to do is not efficient, then what is the best way to do canonicalise all child nodes of <soap:Body> of the above example in Libxml ?
Thank you,Chetan Raj
On 4/14/06, Daniel Veillard <[EMAIL PROTECTED] > wrote:On Fri, Apr 14, 2006 at 12:07:42PM +0530, Chetan Raj wrote:
> Hi All,
>
> I am new to Libxml. I am trying to find an API in Libxml that can give me
> xmlNodeSetPtr for all the children nodes of a xml subtree.
A node set can be one of the results of an XPath query. So you would
have to make an XPath query corresponding to the childrens. But that sounds
wrong to me, if you want to walk the children of a node it's part of the
tree structure so why spend time to create artificially an extra structure
for this !
Daniel
--
Daniel Veillard | Red Hat http://redhat.com/
[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/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
