Javascript obtains the maximum value of an xml node.
This article describes how to use javascript to obtain the maximum value of an xml node. For more information, see.
Suppose the current time is 7000 Ms. When the time is 3000-6000, the value of is taken, that is, the xml value is smaller than the maximum value of the current time.
Xml file,
The Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Catalog>
<Cd>
<ID> 2 </ID>
<Title> lecture 1st </title>
<MediaUrl> 123 </mediaUrl>
<HtmlUrl> 1.html
<OrderNo> 2 </orderNo>
<StudyTimes> 00:00:30 </StudyTimes>
<Secondss times = "30000"> 1.html </Secondss>
</Cd>
<Cd>
<ID> 3 </ID>
<Title> lecture 2nd </title>
<MediaUrl> 123 </mediaUrl>
<HtmlUrl> 2.html
<OrderNo> 2 </orderNo>
<StudyTimes> 00:01:00 </StudyTimes>
<Secondss times = "60000"> 2.html </Secondss>
</Cd>
<Cd>
<ID> 4 </ID>
<Title> lecture 3rd </title>
<MediaUrl> 123 </mediaUrl>
<HtmlUrl> 3.html
<OrderNo> 2 </orderNo>
<StudyTimes> 00:01:30 </StudyTimes>
<Secondss times = "90000"> 3.html </Secondss>
</Cd>
</Catalog>
Javascript:
MediaPlayer. Controls. CurrentPosition * 1000 is the current time
The Code is as follows:
Function times (){
// Define an array
Var array = new Array ();
// Define the xmldom Protocol
Var xmlDom = new ActiveXObject ("Microsoft. XMLDOM ");
XmlDom. async = false;
// Load the xml file
XmlDom. load (id. value + "_ imsmanifest. xml"); // jump
Try {
// Find all Secondss
X = xmlDom. getElementsByTagName ("Secondss ");
// Traverse
For (I = 0; I <x. length; I ++ ){
// Obtain the times attribute
Var s = x [I]. getAttribute ("times ");
// If the property value is smaller than MediaPlayer. Controls. CurrentPosition * 1000, it is added to the array.
If (s <= MediaPlayer. Controls. CurrentPosition * 1000 ){
Array. push (s );
}
}
// Sort the array. At this time, array [array. length-1] is smaller than the maximum value in MediaPlayer. Controls. CurrentPosition * 1000.
Array. sort ();
}