[xml] Canonicalization (C14N) of an XML element

We are working with XML Digital Signatures, see

I would like to see functions for canonicalization of a single given
XML element,
including its attributes, subelements and contents.

I did not find any such functions, so I made my own functions, see below. 
My problem is that only the given element, *without* its attributes, 
subelements and contents, is canonicalized (output).

E.g. "<xxx></xxx>"

I am a newbie to libxml2, and I am not familiar with XPath, nor
libxml2's NodeSet.
Please tell me if I am going in the wrong direction. 

Here is how I tried to do it:

As far as I can see I can:
- use xmlC14NDocDumpMemory to dump canonicalized to memory 
- use xmlC14NDocSave       to dump canonicalized to file

These functions take the parameter 'xmlNodeSetPtr nodes', described as
"The nodes set to be included in the canonized image, 
or NULL if all document nodes should be included."

So I built a node set, consisting of my single element node.
Should I build a node set including all sub-nodes? 

Here is the source code:

int My_xmlC14NElementDumpMemory(xmlNode* Node_p, xmlChar** DocText_pp)
  int Len = -1;
  if ((NULL != Node_p) && (NULL != DocText_pp))
    xmlNodeSetPtr NodeSet_p = xmlXPathNodeSetCreate(Node_p);
    if (NULL != NodeSet_p)
      Len = xmlC14NDocDumpMemory(
                  1,             //int exclusive
                  NULL,          //xmlChar ** inclusive_ns_prefixes
                  0,             //int with_comments
  return Len;

int My_xmlC14NElementSave(xmlNode* Node_p, char* FilePathAndName_p)
  return -1;  // will use xmlC14NDocSave

Best regards, 
Göran Halfvarson

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]