VC 使用MSXML创建新结点时出现xmlns="" 属性解决方法
2013-04-16 11:00
537 查看
在VC中使用MSXML创建xml文件,在使用下面代码:
问题原因:当父节点具有XMLNS属性时,子节点必须指定XMLNS属性,但是当子节点的XMLNS属性与父节点命名空间相同时,子节点不显示XMLNS属性.
上面问题的根本所在就是我们理解上的错误,我们认为没有为子节点指定命名空间,就不应该出现此属性,恰恰相反,当我们为其指定与父节点相同的命名空间时,此属性才不会出现
那么如何去掉前缀xmlns=""呢?
代码如下::
pXMLSubElementRoot = pDoc->createNode("element","LoginInfo","http://DCMPlatform/v2.0");
pXMLRoot - > a(pXMLSubElementRoot);
而不用createElement_x_x_x_x_x
其中LoginInfo节点名称. http://DCMPlatform/v2.0 是前面定义的名字空间名!
或者是将父节点的信息设置如下,子节点的默认节点名字空间与父节点一样:
父节点修改代码如下:
pXMLRoot
= pDoc->selectSingleNode("DCMCatalogueResult");
pXMLRoot->setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
pXMLRoot->setAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema");
pXMLRoot->setAttribute("xmlns","http://DCMPlatform/v2.0");
[cpp] view
plaincopy
<pre class="cpp" name="code">//创建一个层
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);
</pre>
<pre></pre>
<p>建立一个新结点时,生成的结点中出现xmlns="" 属性,如下xml:</p>
<pre class="html" name="code"><g xmlns="" id="Head_Layer">
<rect x="0" y="0" width="1650" height="906" fill="rgb(0,0,0)"/>
</g></pre>
<p>自动的添加了xmlns="" 属性,查了资料,解决办法如下代码:</p>
<pre class="cpp" name="code">/********引用包含**********/
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);</pre>
<p>使用createNode创建结点。<br>
</p>
问题原因:当父节点具有XMLNS属性时,子节点必须指定XMLNS属性,但是当子节点的XMLNS属性与父节点命名空间相同时,子节点不显示XMLNS属性.
上面问题的根本所在就是我们理解上的错误,我们认为没有为子节点指定命名空间,就不应该出现此属性,恰恰相反,当我们为其指定与父节点相同的命名空间时,此属性才不会出现
那么如何去掉前缀xmlns=""呢?
代码如下::
pXMLSubElementRoot = pDoc->createNode("element","LoginInfo","http://DCMPlatform/v2.0");
pXMLRoot - > a(pXMLSubElementRoot);
而不用createElement_x_x_x_x_x
其中LoginInfo节点名称. http://DCMPlatform/v2.0 是前面定义的名字空间名!
或者是将父节点的信息设置如下,子节点的默认节点名字空间与父节点一样:
父节点修改代码如下:
pXMLRoot
= pDoc->selectSingleNode("DCMCatalogueResult");
pXMLRoot->setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
pXMLRoot->setAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema");
pXMLRoot->setAttribute("xmlns","http://DCMPlatform/v2.0");
[cpp] view
plaincopy
<pre class="cpp" name="code">//创建一个层
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);
</pre>
<pre></pre>
<p>建立一个新结点时,生成的结点中出现xmlns="" 属性,如下xml:</p>
<pre class="html" name="code"><g xmlns="" id="Head_Layer">
<rect x="0" y="0" width="1650" height="906" fill="rgb(0,0,0)"/>
</g></pre>
<p>自动的添加了xmlns="" 属性,查了资料,解决办法如下代码:</p>
<pre class="cpp" name="code">/********引用包含**********/
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);</pre>
<p>使用createNode创建结点。<br>
</p>
相关文章推荐
- VC 使用MSXML创建SVG文档中的新结点时出现xmlns="" 属性解决方法
- 使用CString的方法(以及用VC写DLL中"error LNK2005: _DllMain@12 already defined"的解决办法)
- ie6 li间隙问题 使用float属性是出现空白的解决方法
- 使用 getBytes("iso-8859-1"),"gb2312" 方法仍出现乱码的解决方法
- 关于使用Git的时候出现"HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large"的解决方法
- .net 使用提取模式使用SQL创建报表 出现“您请求的报表需要更多信息.”的解决方法
- hql查询pojo类中关联对象使用关联对象的属性条件时,出现Invalid path: 'xx.xx'的解决方法
- 使用微信SDK时,出现了 "operator new[](unsigned long)", referenced from:等问题的解决方法
- mac系统下使用beego工具创建项目出现kill -9 解决方法
- SQL Server 2005 中,创建新维护计划时出现错误信息:失败" 创建维护计划"14234 解决方法
- C#使用String.Format()方法时,出现异常"输入的字符串格式有误"的解决方法
- 使用fckEditor 出现"检测到有潜在危险的 Request.Form值"的解决方法! (网络整理)
- Word出现"无法创建工作文件,请检查临时环境变量"的解决方法
- phpStudey2010中进入phpMyAdmin出现"无法在发生错误时创建会话,请检查PHP"的解决方法
- Gradle 使用Jetty插件启动web项目时出现"java.lang.OutOfMemoryError: PermGen space"解决方法
- 创建工程使用 cocoapods 时没有出现 xcworkspace 文件解决方法
- 使用eclipse 开发 嵌入式Linux驱动(注意事项)(make:***没有规则可言创建目标"all".停止 的解决方法)
- win 7 删除了用户文件夹后出现的&quot;你已使用临时配置文件登录&quot;提示的解决方法
- SQL Server 2005 中,创建新维护计划时出现错误信息:失败" 创建维护计划"14234 解决方法
- VC轻松解析XML文件--CMarkup使用方法(解决解析中文字符出现乱码问题)