如何使用javascript读取xml文件

时间:2016-08-04 07:48:41

标签: javascript xml

如何从Javascript中的XML中的特定子元素获取值 这是XML

  <?xml version="1.0" encoding="UTF-8"?>
  <Data_Speed>
  <Tech ID = "UMTS">
     <Coverage ID="Dense_Urban">
        <DownLoad_Speed>10</DownLoad_Speed>
        <Upload_Speed>20</Upload_Speed>
     </Coverage>
    <Coverage ID="Urban">
        <DownLoad_Speed>30</DownLoad_Speed>
        <Upload_Speed>40</Upload_Speed>
    </Coverage>
    <Coverage ID="SubUrban">
        <DownLoad_Speed>50</DownLoad_Speed>
        <Upload_Speed>60</Upload_Speed>
    </Coverage>
 </Tech>
 <Tech ID = "UMTS900">
    <Coverage ID="Dense_Urban">
      <DownLoad_Speed>11</DownLoad_Speed>
      <Upload_Speed>12</Upload_Speed>
   </Coverage>
   <Coverage ID="Urban">
      <DownLoad_Speed>13</DownLoad_Speed>
      <Upload_Speed>14</Upload_Speed>
   </Coverage>
   <Coverage ID="SubUrban">
      <DownLoad_Speed>15</DownLoad_Speed>
      <Upload_Speed>16</Upload_Speed>
    </Coverage>
 </Tech>
 <Tech ID = "4G800">
    <Coverage ID="Dense_Urban">
     <DownLoad_Speed>30</DownLoad_Speed>
     <Upload_Speed>42</Upload_Speed>
    </Coverage>
   <Coverage ID="Urban">
     <DownLoad_Speed>50</DownLoad_Speed>
     <Upload_Speed>34</Upload_Speed>
   </Coverage>
   <Coverage ID="SubUrban">
    <DownLoad_Speed>45</DownLoad_Speed>
    <Upload_Speed>46</Upload_Speed>
   </Coverage>
   <Coverage ID="Rural">
     <DownLoad_Speed>47</DownLoad_Speed>
     <Upload_Speed>48</Upload_Speed>
   </Coverage>
   <Coverage ID="Variable">
     <DownLoad_Speed>15</DownLoad_Speed>
     <Upload_Speed>52</Upload_Speed>     
   </Coverage>
   <Coverage ID="Outdoor">
     <DownLoad_Speed>25</DownLoad_Speed>
     <Upload_Speed>22</Upload_Speed>
   </Coverage>
</Tech>
</Data_Speed>

那我怎么能得到DownLoad_Speed的价值&gt; &安培; UpLoad_Speed&GT;给定Coverage ID Urban的元素&gt;和技术ID UMTS900&gt;?比方说,如果我给出技术ID值=&#34; UMTS900&#34;和覆盖ID值&#34; Urban&#34;,我希望使用Java脚本将字符串值dwnload_speed = 13和Upload_Speed = 14作为结果

0 个答案:

没有答案