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

来源:互联网 发布:apache sh commands 编辑:程序博客网 时间:2024/06/05 23:41


 在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创建结点。

原创粉丝点击