您的位置:首页 > 其它

VC 使用MSXML创建SVG文档中的新结点时出现xmlns="" 属性解决方法

2011-11-18 20:11 295 查看
在VC中使用MSXML创建SVG,在使用下面代码:

//创建一个层
pLeyer = pDoc->createElement((_bstr_t)"g");
pLeyer->setAttribute("id","Head_Layer");
//创建一个节点
pNode = pDoc->createElement((_bstr_t)"rect");
pNode->setAttribute("x","0");
pNode->setAttribute("y","0");
pNode->setAttribute("width","1650");
pNode->setAttribute("height","906");
pNode->setAttribute("fill","rgb(0,0,0)");
//添加节点到层
pLeyer->appendChild(pNode);
//将层添加到根
xmlRoot->appendChild(pLeyer);


建立一个新结点时,生成的结点中出现xmlns="" 属性,如下xml:

<g xmlns="" id="Head_Layer">
<rect x="0" y="0" width="1650" height="906" fill="rgb(0,0,0)"/>
</g>

自动的添加了xmlns="" 属性,查了资料,解决办法如下代码:

/********引用包含**********/
VARIANT   vtTemp;
vtTemp.vt   =   VT_I2;
vtTemp.iVal   =   1;
_bstr_t   namespaceURI="http://www.w3.org/2000/svg";

//创建一个层
pLeyer = pDoc->createNode(vtTemp,(_bstr_t)"g",namespaceURI);
pLeyer->setAttribute("id","Head_Layer");
//创建一个节点
pNode = pDoc->createNode(vtTemp,(_bstr_t)"rect",namespaceURI);
pNode->setAttribute("x","0");
pNode->setAttribute("y","0");
pNode->setAttribute("width","1650");
pNode->setAttribute("height","906");
pNode->setAttribute("fill","rgb(0,0,0)");
//添加节点到层
pLeyer->appendChild(pNode);
//将层添加到根
xmlRoot->appendChild(pLeyer);

使用createNode创建结点。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐