-1

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")
5
  • If objXmlSimpleTypeDoc is an XElement then you can use objXmlEnumerationValueNode = objXmlSimpleTypeDoc.Elements("EnumerationValue").Where(Function(el) el.Attribute("code").Value = strCourtNCIC).ToList(). Ref: Get XElement by value of its attribute. Aug 12, 2019 at 17:48
  • objXmlSimpleTypeDoc is declared as Dim objXmlSimpleTypeDoc As System.Xml.XmlDocument. I am getting an error objXmlSimpleTypeDoc As XmlDocument 'Elements' is not a member of 'XmlDocument' Aug 13, 2019 at 14:02
  • Yes, that would only have worked if objXmlSimpleTypeDoc was an XElement, but I couldn't see its declaration in the question so I could only guess. Aug 13, 2019 at 14:11
  • Hi Andrew, thanks for your input on this. Based on your knowledge, what do you recommend I can do? Aug 13, 2019 at 14:42
  • Have a go with objXmlEnumerationValueNode = doc.SelectSingleNode("//SimpleTypeCompanion/EnumerationValue[@code='" & strCourtNCIC & "']"), ref: Search XML file for nodes with specific attribute value in .NET 2. Aug 13, 2019 at 15:16

1 Answer 1

0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.