| |

VerySource

 Forgot password?
 Register
Search
View: 606|Reply: 4

Javascript gets the children of a node.

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Taiwan

Post time: 2020-1-2 20:00:01
| Show all posts |Read mode
<? xml version = "1.0"?>
<data>
  <item>
     <a> a </a>
     <b> b </ b>
  </ item>
  <item>
     <c> c </ c>
     <d> c </ d>
  </ item>
</ data>
For example, in an XML document like the above, I want to use JavaScript DOM to get the values ​​of the child nodes a, b, c, and d under the <item> node. What should I do?
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-3 22:45:01
| Show all posts
Come on,
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-5 01:42:01
| Show all posts
var xmlDoc = new ActiveXObject ("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.load ("music.xml");
var nodes = xmlDoc.documentElement.childNodes;
nodes.item (x) .childNodes [y] .text;
x, y represents the corresponding index
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-5 15:57:01
| Show all posts
But what to do with cycling?
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-11 10:00:02
| Show all posts
var l = nodes.length
for (var i = 0; i <l; i ++)
nodes.item (i) .childNodes [0] .text + nodes.item (i) .childNodes [1] .text
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list