[xmlsec] About xmlParseInNodeContext() in libxml2.

Tomas Sieger tomas.sieger at systinet.com
Wed Sep 15 04:16:50 PDT 2004

Hi Stack,
  I was also faced with this problem and I had to solve it several 
months ago. What I did was I hacked

       xmlNodePtr node,
       const xmlSecByte *buffer,
       xmlSecSize size)

  in such an ugly way that when putting a 'buffer' into a document 
(replacing some 'node' in the document), I:

i) gathered ALL namespace declarations affecting the 'node' to be 
replaced (by the decrypted data), i.e. all namespace declarations on the 
"ancestor-or-self axis".

ii) added all the gathered namespace declarations at the <dummy> context 
which is used when parsing the 'buffer'

iii) parsed the 'buffer' in the <dummy xmlns:p1=v1 ...> context, thus 
all the non-local namespace declaration were successfully "saturated" at 
the <dummy ...> context element, so namespaces were parsed OK

iv) next, I repaired (repointed) all the (non-local) namespace usages in 
'doc' to point not to the declarations at the <dummy> element, but to 
the original namespaces declarations in the original document (where 
'node' existed in)

and next, I hacked xmlSecEncCtxDecrypt() to use my hacked version of 

Write me if you need more help following this complex hack (e.g. to send 
sources). But I admit your solution using xmlParseInNodeContext() is 
much more elegant and correct (but the context parsing was not available 
at the time I was faced with the problem).

But note your problem is a known bug:
and it is already being solved. So the best thing to do is probably to 
ask xmlSec (libxml2) people when a new version of xmlSec fixing this bug 
is coming out, possibly help them with fixing / testing.

See also
(discussing xmlSec dependency on libxml2 2.6.12, which is necessary to 
fix the bug).

hope it helps,

StackWD(hotmail) wrote:
> Hi!
>   I'm sorry to say although I have inserted those two lines as below, the error is so. But I have found an interesting things, if remove the attribute xsi:type=\"xsd:int\" of buffer, that's OK!
>   It's important that I want to solve the problem of Encryption and namespace viewed of Mailing list in web site. Now we MUST encrypt the soap such as below, but when decryption the namespace of xsi not found where it defined. I want know how to solve this old problem (may be already solved) or give me some advice. 
>>Can you try to insert the two lines from bellow? If it will not work
>>then it would be a good idea to file a bug against LibXML2
>>I'll try to look at this more this weekend (sorry, but I doubt that I'll
>>have time before that).
>>>    char *buffer = "<xsi:getsumReturn xsi:type=\"xsd:int\">9</xsi:getsumReturn>";
>>>    xmlInitParser();
>>>    xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
>>>    xmlSubstituteEntitiesDefault(1);
>>>    /* load template */
>>>    doc = xmlParseFile("soap.xml");
>>>    if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)){
>>>        fprintf(stderr, "Error: unable to parse file \"%s\"\n", "soap.xml");
>>>        goto done;
>>>    }
>>>    ret = xmlParseInNodeContext(xmlDocGetRootElement(doc), buffer, xmlStrlen(buffer), XML_PARSE_NOENT, &encNode);
>>>    if(ret < 0) {
>>>        fprintf(stderr, "Error: xmlParseInNodeContext.\n");
>>>        goto done;
>>>    }
>>AS ====> xmlUnlinkNode(encNode);
>>AS ====> xmlSetTreeDoc(encNode, doc);
>>>    xmlAddChild(xmlDocGetRootElement(doc), encNode);
>>>    xmlDocDump(stdout, doc);
>>>    xmlFreeDoc(doc);  <----- The error : Segmentation fault occur!
>         StackWD(hotmail)
>         StackWD at hotmail.com
>           2004-09-15
> _______________________________________________
> xmlsec mailing list
> xmlsec at aleksey.com
> http://www.aleksey.com/mailman/listinfo/xmlsec

More information about the xmlsec mailing list