首页 > 解决方案 > 如何找到与变量值匹配的特定节点?

问题描述

有人可能会说这个问题与上一个问题相似,但它也不同。我有 ObjXmlSimpleTypeDoc 对象,它有两个 EnumerationValue 节点。每个 EnumerationValue 都有子节点。

我只想找到正确的 EnumerationValue 节点,它的 @code 与变量 strCourtNCIC 中的值匹配。在这个问题中 strCourtNCIC=MN010015J。对于这个问题,strCourtNCIC 保存一个值 MN010015J。

如何在 VB.NET 中执行此操作?我的 VB.NET 代码为 objXmlEnumerationValueNode 返回 Nothing,即使我希望看到带有 @code = MN010015J 的节点

如何更改我的 VB.NET 代码行以使用与 strCourtNCIC 值匹配的@code 查找 EnumerationValue 节点?

这是对象 ObjXmlSimpleTypeDoc

<SimpleTypeCompanion enumerates="CourtLocationTextType">
    <EnumerationValue code="MN010015J">
        <Text>Emily County</Text>
        <AssociatedValue type="MNCISNodeID">
            <Text>111</Text>
        </AssociatedValue>
        <AssociatedValue type="CountyName">
            <Text>Emily</Text>
        </AssociatedValue>
        <AssociatedValue type="PhoneNumber">
            <Text>724-820-7123</Text>
        </AssociatedValue>
    </EnumerationValue>
    <EnumerationValue code="DC19DAKDC">
        <Text>Pope County</Text>
        <AssociatedValue type="MNCISNodeID">
            <Text>112</Text>
        </AssociatedValue>
        <AssociatedValue type="CountyName">
            <Text>Pope</Text>
        </AssociatedValue>
    </EnumerationValue>
</SimpleTypeCompanion>

这是我需要帮助才能获得与 strCourtNCIC (MN010015J) 匹配的正确 EnumerationValue 的 VB.NET 代码。

    'CourtNCIC 
strCourtNCIC = objXmlMNCISData.DocumentElement.SelectSingleNode("Case/Court/CourtNCIC").InnerText
'Access the CourtLocationTextType simple type. 
objXmlSimpleTypeDoc = Msc.Integration.CourtXml.Library.v4.SimpleType.GetCompanionFile("CourtLocationTextType")
'Get the correct EnumerationValue node that has @code =MN010015J string value
objXmlEnumerationValueNode = objXmlSimpleTypeDoc.SelectSingleNode("/SimpleTypeCompanion/EnumerationValue[@code=" + strCourtNCIC + "]/@code")

标签: xmlvb.net

解决方案


这是我的解决方案。这是值周围缺少单引号的情况!

objXmlEnumerationValueNode = objXmlSimpleTypeDoc.SelectSingleNode("/SimpleTypeCompanion/EnumerationValue[@code='" + strCourtORI + "']")

推荐阅读