2015-04-24 76 views
1

所有节点我有一个XML查找与属性相匹配的模式

<mic_root state="mismatch"> 
    <RepoTrade state="mismatch"> 
    <TradeIds state="mismatch"> 
     <TradeId state="mismatch"> 
     <Id state="missing" /> 
     <Id1 state="added" /> 
     <Version state="mismatch"> 
      <mic_elemA_text>1</mic_elemA_text> 
      <mic_elemB_text>2</mic_elemB_text> 
     </Version> 
     </TradeId> 
     <TradeId state="mismatch"> 
     <Id state="mismatch"> 
      <mic_elemA_text>1</mic_elemA_text> 
      <mic_elemB_text>2</mic_elemB_text> 
     </Id> 
     </TradeId> 
    </TradeIds> 
    <Fixings state="mismatch"> 
     <mic_elemA_text> 
     </mic_elemA_text> 
     <mic_elemB_text>123</mic_elemB_text> 
    </Fixings> 
    <SpecificDetail state="mismatch"> 
     <DirtyBondPrice mic_elemA_attr="%s=&quot;%s&quot;;%s=&quot;%s&quot;" mic_elemB_attr="%s=&quot;%s&quot;;%s=&quot;%s&quot;" state="mismatch" /> 
    </SpecificDetail> 
    </RepoTrade> 
</mic_root> 

我需要找到所有那些有像mic_elem属性节点?_ ?????。例如,在上面的XML中,我需要获得DirtyBondPrice。我可以找到所有那些与代码类似的模式是这样的节点:

Set xmlMatches = objResultsXML.GetRootElement.ChildElementsByPath("//*[starts-with(local-name(), 'mic_elem')]") 

这让我像<Version><mic_elemA_text><mic_elemB_text> & <Id><mic_elemA_text><mic_elemB_text>所有节点。

回答

2

可以采用同样的方法为属性为你做的节点:

//*[@*[starts-with(local-name(), 'mic_elem')]] 

不会导致精确模式:mic_elem?_?????而是:mic_elem?????。这可能就够了,因为后者的模式足以用于按名称查找节点。

+0

谢谢,这就像一个魅力。不能相信我没有尝试过这种组合。我需要了解更多关于xpath的信息。 –