我有一个简单的xml,其中包含多个InterimConditionEvent
ID。我想获得具有最高价值的InterimConditionEvent ID
。
对于我的xml,我想获得<InterimConditionEvent ID="160850209">
因为它具有最高价值。
我如何在VB.Net中做到这一点?
我的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>
在我的vb.net代码中,我使用的是最后一个位置,但我意识到这可能会返回没有最新日期或时间的最后位置。 这是我的vb.net最后一个位置代码,我想更改为使用具有最高值的ID。
strOrderEndDate = objXmlCaseDoc
.DocumentElement
.SelectSingleNode("Case/InterimConditionEvent[position()=last()]/InterimCondition[ConditionType/@Word='DOMNC']/EndDate").InnerText
答案 0 :(得分: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()