如何仅从具有VBA EXCEL(VBA DOM)XML中的特定属性的节点中检索值。

时间:2016-08-09 20:09:30

标签: vba excel-vba dom excel

我只需要从属性为“true”的节点中检索值。这就是我拥有的和我需要的 - 感谢任何帮助:

public string deviceName;
WebCamTexture wct;
void Start ()
{
    WebCamDevice[] devices = WebCamTexture.devices;
    deviceName = devices[0].name;
    wct = new WebCamTexture(deviceName, 400, 300, 12);
    GetComponent<Renderer> ().material.mainTexture = wct;
    wct.Play();
}

这是我的代码,它将检索所有值,但我想找到一种只检索ENG和POR(true)的方法。我似乎无法找到合适的方法来做到这一点。

    <AudioTracks>
      <original available="true">ENG</original>
      <localized available="false">SPA</localized>
      <localized available="true">POR</localized>
    </AudioTracks>

这将使我返回ENG; SPA; POR ......但我需要它才能返回ENG; POR

  

帮助我欧比万,你是我唯一的希望。

1 个答案:

答案 0 :(得分:0)

尤里卡。我找到了实现这一目标的方法。不漂亮,但工作得很好!我刚刚使用getAttribute属性做了一个小条件。作为参数,我刚刚使用了属性名称(在本例中为“available”)。哈!美丽 - 对我来说。

    Set oAudioNodes = featureNode.SelectSingleNode("videos/video/AudioTracks")

    txt = ""

    For i = 0 To oAudioNodes.ChildNodes.Length


          txt = oAudioNodes.ChildNodes.Item(i).getAttribute("available")

If txt = "true" Then sAudio = oAudioNodes.ChildNodes.Item(i).nodeTypedValue & ";" & sAudio

    Next

    sAudio = Left(sAudio, Len(sAudio) - 1)
    ActiveSheet.Cells(intRow, colAudioTracks).Value = NullCheck(sAudio)
    sAudio = ""
    sRawData = ""
    txt = ""