DOM解析非默认命名空间xml文件时,selectSingleNode返回0,求大侠相助

yanxiaofang0504 2012-05-14 01:11:30
利用dom解析一个xml文件,我想获取\Model\packagedElement 路径下“name”属性值为“dinggou”的ownedAttribute节点,可是利用selectSingleNode()返回的总是0,这是为啥呢?
要解析的xml如下:
  <?xml version="1.0" encoding="UTF-8" ?> 
- <uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" xmi:id="_kkgsMBeLEd60N8ipLbB6nA" name="Atmosphere">
- <packagedElement xmi:type="uml:Class" xmi:id="_0Ot84JwMEeGMlsuVTnw_dg" name="Atmosphere">
<ownedAttribute xmi:id="_0Sb_QJwMEeGMlsuVTnw_dg" name="_isTarget" visibility="private" isStatic="true" type="_0TB1IJwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0TB1IZwMEeGMlsuVTnw_dg" name="dinggou" visibility="public" type="_0TehEJwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0TLmIJwMEeGMlsuVTnw_dg" name="fabu" visibility="public" type="_0UOH8JwMEeGMlsuVTnw_dg" />
</packagedElement>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_0TB1IJwMEeGMlsuVTnw_dg" name="bool" />
- <packagedElement xmi:type="uml:Class" xmi:id="_0TehEJwMEeGMlsuVTnw_dg" name="LocationData">
<ownedAttribute xmi:id="_0ToSEJwMEeGMlsuVTnw_dg" name="longitude" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0ToSEpwMEeGMlsuVTnw_dg" name="latitude" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0TxcAJwMEeGMlsuVTnw_dg" name="height" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0TxcAZwMEeGMlsuVTnw_dg" name="position_ang" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0T7NAJwMEeGMlsuVTnw_dg" name="pitch_ang" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0T7NAZwMEeGMlsuVTnw_dg" name="roll_ang" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
</packagedElement>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_0ToSEZwMEeGMlsuVTnw_dg" name="double" />
- <packagedElement xmi:type="uml:Class" xmi:id="_0UOH8JwMEeGMlsuVTnw_dg" name="AtmData">
<ownedAttribute xmi:id="_0UX48JwMEeGMlsuVTnw_dg" name="wind" visibility="public" type="_0Uz90JwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0UX48ZwMEeGMlsuVTnw_dg" name="temprature" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0UhC4JwMEeGMlsuVTnw_dg" name="cloud" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0UhC4ZwMEeGMlsuVTnw_dg" name="fog" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0Uqz4JwMEeGMlsuVTnw_dg" name="visibility" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
</packagedElement>
- <packagedElement xmi:type="uml:Class" xmi:id="_0Uz90JwMEeGMlsuVTnw_dg" name="wind">
<ownedAttribute xmi:id="_0U9u0JwMEeGMlsuVTnw_dg" name="wind_u" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0VHf0JwMEeGMlsuVTnw_dg" name="wind_v" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
<ownedAttribute xmi:id="_0VHf0ZwMEeGMlsuVTnw_dg" name="wind_w" visibility="public" type="_0ToSEZwMEeGMlsuVTnw_dg" />
</packagedElement>
</uml:Model>


我编写的selectSingleNode段的代码如下:
	MSXML2::IXMLDOMDocument2Ptr pXMLDom;
HRESULT hr;
CoInitialize(NULL);

hr = pXMLDom.CreateInstance(__uuidof(MSXML2::DOMDocument));
if (FAILED(hr))
{
printf("Failed to CreateInstance on an XML DOM");
return;
}

VARIANT_BOOL isSuccessFul=pXMLDom->load(atmFileName);
MSXML2::IXMLDOMNodePtr pNode;
if (isSuccessFul==VARIANT_TRUE)
{
pXMLDom->setProperty("SelectionLanguage","XPath");
pXMLDom->setProperty("SelectionNamespaces","xmlns:uml='http://www.eclipse.org/uml2/2.1.0/UML' xmlns:xmi='http://schema.omg.org/spec/XMI/2.1'");

pNode=pXMLDom->selectSingleNode(L"/Model/packagedElement/ownedAttribute[@name='dinggou']");
}

为什么总是得不到节点呢?查了查有人说和命名空间有关,是哪里出问题了呢?求各位大侠指点!小妹感激不尽!
...全文
82 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yanxiaofang0504 2012-05-14
多谢啊,刚才调试的时候也发现了改好了,还是很感谢~~
回复
孟子E章 2012-05-14
pNode=pXMLDom->selectSingleNode(L"/uml:Model/packagedElement/ownedAttribute[@name='dinggou']");

名称空间没用上啊
回复
相关推荐
发帖
VC.NET
创建于2007-09-28

7540

社区成员

.NET技术 VC.NET
申请成为版主
帖子事件
创建了帖子
2012-05-14 01:11
社区公告
暂无公告