How to add a xml node constructed from string in libxml2

后端 未结 4 605
栀梦
栀梦 2021-02-09 13:34

I am using Libxml2 for encoding the data in a xml file. My data contain tags like \"<\" and \">\". when it is converted into xml these tags are also converted into \"<\

4条回答
  •  天涯浪人
    2021-02-09 13:48

    You can try to use function xmlParseInNodeContext. It allows you to parse raw XML in the context of parent node, and constructs a node that can be attached to the parent.

    For example:

    const char * xml = "blah";
    xmlNodePtr new_node = NULL;
    
    // we assume that 'parent' node is already defined
    xmlParseInNodeContext(parent, xml, strlen(xml), 0, &new_node);
    if (new_node) xmlAddChild(parent, new_node);
    

提交回复
热议问题