Javascript obtains the maximum value of an xml node.

Source: Internet
Author: User

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 ();

}

Related Article

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.