需要在c++中为xml文档提供一个通过xpath导航的算法



在下面的XML文档中。。。

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<x:Response xmlns:xcr="http:sefgvsefraerdv">
<folder id='82273' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns'http://srdefaredr/folders.xsd'>
<folder id='104018' name='account'/>
<folder id='104019' name='aaaaa'/>
<folder id='82277' name='Desktop' system='desktop'/>
<folder id='82278' name='Trashcan' system='trashcan'/>
<folder id='82279' name='Documents'>
       <folder id='82280' name='Music'/>
       <folder id='82281' name='Pictures'>
            <folder id='82282' name='Nature Album'/>
       </folder>
</folder>
<folder id='82283' name='Public' system='public'/>
<folder id='82284' name='music1'/>
<folder id='82286' name='music'>
     <folder id='105744' name='abba'/>
</folder>
</folder>
</x:Response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我需要获取所有的文件夹ID并打印它们。

例如,我的导航方式如下:

  xpath.evaluate( /*/*/*/*/*[5]) 

我将获取文档中的所有文件夹。然后我需要给/*/*/*/*/*[5]/*获得音乐和图片,/*/*/*/*/*[5]/*/*只获得学士学位。

然后一直返回到/*/*/*/*/*[6]并继续相同的操作。。

获取所有ids:

//folder/@id

如果你有notepad++,有一个用于测试xpath的xpath插件。

最新更新