查找属性与模式匹配的所有节点

Find all nodes with attribute that matches a pattern

我有一个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>

您可以对属性应用与对节点相同的方法:

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

不会产生确切的模式:mic_elem?_?????,而是:mic_elem?????。这可能就足够了,因为后一种模式被认为足以按名称查找节点。