1、
2、例子代码:
int TgText::NodeNew_G2SVG(xmlNode* _pNodeCurrent_G, xmlNode* _pNodeParent_SVG, xmlNode** _ppNodeNew_SVG) { //// ZC: SVG 方式 //*_ppNodeNew_SVG = ChildNodeCreate(_pNodeParent_SVG, "text"); // ZC: 内嵌HTML方式 xmlNode* pNode_switch = ChildNodeCreate(_pNodeParent_SVG, "switch"); xmlNode* pNode_foreignObject = ChildNodeCreate(pNode_switch, "foreignObject"); //xmlSetProp(pNode_foreignObject, BAD_CAST "x", BAD_CAST ""); //xmlSetProp(pNode_foreignObject, BAD_CAST "y", BAD_CAST ""); xmlSetProp(pNode_foreignObject, BAD_CAST "width", BAD_CAST TextWidth_switch_foreignObject); xmlSetProp(pNode_foreignObject, BAD_CAST "height", BAD_CAST TextHeight_switch_foreignObject); xmlNode* pNode_p = ChildNodeCreate(pNode_foreignObject, "p"); xmlSetProp(pNode_p, BAD_CAST "xmlns", BAD_CAST "http://www.w3.org/1999/xhtml"); { // <switch/>下面的<text/> xmlNode* pNode_text = ChildNodeCreate(pNode_switch, "text"); xmlNode* pContent = xmlNewText(BAD_CAST "<p>Your SVG viewer cannot display html.</p>"); xmlAddChild(pNode_text, pContent); //xmlNewDocRawNode(pNode_text->doc, NULL, BAD_CAST "p", BAD_CAST "Your SVG viewer cannot display html."); xmlNode* p = xmlNewTextChild(pNode_text, NULL, BAD_CAST "p", BAD_CAST "Your SVG viewer cannot display html."); xmlSetProp(p, BAD_CAST "font-size", BAD_CAST "16px"); } *_ppNodeNew_SVG = pNode_p; return 0; }
2.1、上面的代码,主要的目的是 在 <text/>下添加节点内容 “<p>Your SVG viewer cannot display html.</p>”,效果如下:
<text><p>Your SVG viewer cannot display html.</p><p font-size="16px">Your SVG viewer cannot display html.</p></text>
(1)、但是 函数xmlNewText(...) 会将 尖括号 翻译成 “<”和“>”
(2)、xmlNewTextChild(...) 却可以 达到这个效果,还能对 返回的节点指针进行 属性操作
ZC:关注一下 这个函数xmlNewDocRawNode(...),个人感觉 应该也可以,可能是这样设置参数:
XMLPUBFUN xmlNodePtr XMLCALL
xmlNewDocRawNode (xmlDocPtr doc,
xmlNsPtr ns,
const xmlChar *name,// ZC:这里填 节点的tagname
const xmlChar *content // ZC:这里填 节点里面的 文本内容
);
然后对返回的 节点指针 进行操作,如 “xmlAddChild(父节点, 返回的节点指针);” 、属性操作 等 (只是 猜想,待测试)
3、
4、
5、