我正在使用Vb.net,我需要從以下XML中獲取訪問的最大值。從XML獲取列表節點的最大值
<Pages>
<Page posted="2006-03-27" visits="148" title="Don't Sweep That Under the Rug!"/>
<Page posted="2006-07-12" visits="191" title="Tire Swings for Grownups"/>
<Page posted="2006-11-07" visits="214" title="Eliminate Hornets from Your Picnic"/>
<Page posted="2006-06-14" visits="296" title="Why Ants Invade Your Kitchen"/>
<Page posted="2006-01-15" visits="227" title="101 Ways to Climb a Tree"/>
<Page posted="2006-07-28" visits="133" title="The Beauty of a Frost-Free Refrigerator"/>
<Page posted="2006-03-31" visits="316" title="How to Achieve Restful Sleep"/>
<Page posted="2006-09-21" visits="232" title="Buying Your First Car"/>
</Pages>
我試了下面的代碼,它工作正常。
Dim Node As XmlNode = XmlDocumnet.SelectSingleNode("/Pages/Page/@visits[not(. <= ../preceding-sibling::Page/@visits) and not(. <=../following-sibling::Page/@visits)]")
If Node IsNot Nothing AndAlso Node.Value <> "" Then
MaxVisit= Convert.ToInt32(Node.Value) + 1
End If
但是,如果Visist屬性具有重複值,則找不到它。 即,如果發現重複訪問並且還存在空訪問,則不存在最大值。
對於如:
<Page posted="2006-07-12" visits="214" title="Tire Swings for Grownups"/>
<Page posted="2006-11-07" visits="214" title="Eliminate Hornets from Your Picnic"/>
或:
<Page posted="2006-07-12" visits="" title="Tire Swings for Grownups"/>
<Page posted="2006-11-07" visits="214" title="Eliminate Hornets from Your Picnic"/>
你是什麼意思「找不到正確的」? – Markus
如果發現重複訪問,則不存在最大值。 –
-webkit-box-shadow:0 0 10px 0px#110B0B inset; –