首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

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

2012-05-16 
DOM解析非默认命名空间xml文件时,selectSingleNode返回0,求大侠相助利用dom解析一个xml文件,我想获取\Mode

DOM解析非默认命名空间xml文件时,selectSingleNode返回0,求大侠相助
利用dom解析一个xml文件,我想获取\Model\packagedElement 路径下“name”属性值为“dinggou”的ownedAttribute节点,可是利用selectSingleNode()返回的总是0,这是为啥呢?
要解析的xml如下:

XML code
  <?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段的代码如下:
C/C++ code
    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']");    }

为什么总是得不到节点呢?查了查有人说和命名空间有关,是哪里出问题了呢?求各位大侠指点!小妹感激不尽!

[解决办法]
pNode=pXMLDom->selectSingleNode(L"/uml:Model/packagedElement/ownedAttribute[@name='dinggou']");

名称空间没用上啊

热点排行