1

I have a simple xml with several InterimConditionEvent ID's. I would like to get the InterimConditionEvent ID with the highest value.

For my xml I would like to get <InterimConditionEvent ID="160850209"> because this has the highest value.

How do I do that in VB.Net?

My xml

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper">
<Case InternalID="1617095448" ID="12131576" xmlns:user="http://tylertechnologies.com">
    <InterimConditionEvent ID="160850198">
        <OrderDate>08/14/2015</OrderDate>
        <ExpirationDate>08/14/2015</ExpirationDate>
        <TimestampCreate>08/14/2015 11:01:57:700</TimestampCreate>
        <TimestampChange>08/14/2015 11:21:51:623</TimestampChange>
        <Deleted>true</Deleted>
        <InterimCondition>
            <ConditionType Word="DOMNC">Domestic No Contact</ConditionType>
            <EffectiveDate>8/14/2015</EffectiveDate>
            <EndDate>8/21/2015</EndDate>
        </InterimCondition>
    </InterimConditionEvent>
    <InterimConditionEvent ID="160850209">
        <OrderDate>08/14/2015</OrderDate>
        <ExpirationDate>08/14/2015</ExpirationDate>
        <TimestampCreate>08/14/2015 11:22:28:900</TimestampCreate>
        <TimestampChange>08/14/2015 11:31:15:890</TimestampChange>
        <Deleted>true</Deleted>
        <InterimCondition>
            <ConditionType Word="DOMNC">Domestic No Contact</ConditionType>
            <EffectiveDate>8/14/2015</EffectiveDate>
            <EndDate>8/14/2015</EndDate>
        </InterimCondition>
    </InterimConditionEvent>
</Case>

In my vb.net code, I am using the last position but I realized this could return last position that do not have the latest date or time. Here is my vb.net last position code which I would like to change to use ID with the highest value.

strOrderEndDate = objXmlCaseDoc
    .DocumentElement
    .SelectSingleNode("Case/InterimConditionEvent[position()=last()]/InterimCondition[ConditionType/@Word='DOMNC']/EndDate").InnerText
T.S.
  • 18,195
  • 11
  • 58
  • 78
  • Not sure, but maybe this thread can help you: http://stackoverflow.com/questions/1128745/how-can-i-use-xpath-to-find-the-minimum-value-of-an-attribute-in-a-set-of-elemen – sstan Aug 17 '15 at 15:11

1 Answers1

1

Please try Linq to XML:

Dim xDoc As XElement = XElement.Load("file.xml")

Dim conditionEvents = xDoc.Element("Case").Elements("InterimConditionEvent")

Dim maxId As String = conditionEvents.Attributes("ID").Max(Function(attr) attr.Value)

Dim eventNode As XElement = (From elem In conditionEvents
                             Where elem.Attribute("ID").Value = maxId
                             Select elem).Single()
Alexander Petrov
  • 13,457
  • 2
  • 20
  • 49