简体   繁体   中英

How do I find a specific node that matches a variable value?

Some may say this question is similar to a previous question and it is but it is also different. I have ObjXmlSimpleTypeDoc object which have two EnumerationValue nodes. Each of EnumerationValue have child nodes.

I just want to find the correct EnumerationValue node which has @code that matches the value in the variable strCourtNCIC. In this question strCourtNCIC= MN010015J. For this question strCourtNCIC hold a value MN010015J.

How do I do this in VB.NET? My VB.NET code returns Nothing for objXmlEnumerationValueNode even though I am expecting to see the node with @code = MN010015J

How do I change my VB.NET line of code to find EnumerationValue node with @code that matches strCourtNCIC value?

Here is the object 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>

Here is the VB.NET code that I need help with to just get the correct EnumerationValue that matches strCourtNCIC (MN010015J).

    '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")

Here is my solution. It was the case of missing single quotes around the value!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM