JavaScript gets the maximum value of an XML node (implementation code) _javascript tips

Source: Internet
Author: User

Suppose the current time is now 7000 milliseconds. When the time is 3000--6000 is to go 3000 value, when 6000--9000, take 6000 of the value, that is, the maximum value of the XML is less than the current time

XML file,

Copy Code code as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<catalog>
<cd>
<ID>2</ID>
<title> 1th Lecture </title>
<mediaUrl>123</mediaUrl>
<orderNo>2</orderNo>
<StudyTimes>00:00:30</StudyTimes>
<secondss times= "30000" >1.html</Secondss>
</cd>
<cd>
<ID>3</ID>
<title> 2nd Lecture </title>
<mediaUrl>123</mediaUrl>
<orderNo>2</orderNo>
<StudyTimes>00:01:00</StudyTimes>
<secondss times= "60000" >2.html</Secondss>
</cd>
<cd>
<ID>4</ID>
<title> 3rd Lecture </title>
<mediaUrl>123</mediaUrl>
<orderNo>2</orderNo>
<StudyTimes>00:01:30</StudyTimes>
<secondss times= "90000" >3.html</Secondss>
</cd>
</catalog>

Javascript:

MediaPlayer.Controls.CurrentPosition * 1000 for current time

Copy Code code as follows:

Function times () {
Defining array Arrays
var array =new array ();
Define XMLDOM protocol
var xmldom =new ActiveXObject ("Microsoft.XMLDOM");
Xmldom.async =false;
Load XML file
Xmldom.load (Id.value + "_imsmanifest.xml"); Jump
try {
Find all the SECONDSS.
x = Xmldom.getelementsbytagname ("Secondss");
Traverse
for (I =0 < x.length; i++) {
Fetch Times Property
var s = X[i].getattribute ("Times");
Add to array if property value is less than MediaPlayer.Controls.CurrentPosition * 1000
if (s <= MediaPlayer.Controls.CurrentPosition *1000) {
Array.push (s);
}
}
Sort array at this time array[array.length-1] is less than the maximum value of MediaPlayer.Controls.CurrentPosition * 1000
Array.Sort ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.