代码之家  ›  专栏  ›  技术社区  ›  Vaxo Basilidze

无法使用XML元素的属性获取其内部HTML

  •  4
  • Vaxo Basilidze  · 技术社区  · 6 年前

    <satellites>
    <sat name="NSS 9/Yamal 300K (177.0W)" flags="0" position="-1770">
        <transponder frequency="3792000" symbol_rate="2048000" polarization="1" fec_inner="2" system="1" modulation="1"/>
        <transponder frequency="3987000" symbol_rate="8950000" polarization="1" fec_inner="2" system="0" modulation="1"/>
        <transponder frequency="3999000" symbol_rate="2960000" polarization="1" fec_inner="3" system="0" modulation="1"/>
        <transponder frequency="4055000" symbol_rate="11000000" polarization="0" fec_inner="1" system="1" modulation="1"/>
        <transponder frequency="4099000" symbol_rate="30000000" polarization="1" fec_inner="7" system="1" modulation="1"/>
        <transponder frequency="4163000" symbol_rate="2644000" polarization="1" fec_inner="3" system="1" modulation="1"/>
    </sat>
    <sat name="AMC 8/18 (139.0W)" flags="0" position="-1390">
        <transponder frequency="4056000" symbol_rate="13250000" polarization="0" fec_inner="3" system="0" modulation="1"/>
    </sat>
    <sat name="AMC 10 (135.0W)" flags="0" position="-1350">
        <transponder frequency="3780000" symbol_rate="30000000" polarization="0" fec_inner="3" system="1" modulation="2"/>
        <transponder frequency="3820000" symbol_rate="29270000" polarization="0" fec_inner="3" system="0" modulation="1"/>
        <transponder frequency="4080000" symbol_rate="29270000" polarization="1" fec_inner="3" system="0" modulation="1"/>
        <transponder frequency="4136000" symbol_rate="19510000" polarization="0" fec_inner="3" system="0" modulation="1"/>
        <transponder frequency="4149000" symbol_rate="9760000" polarization="0" fec_inner="3" system="0" modulation="1"/>
        <transponder frequency="4180000" symbol_rate="29270000" polarization="0" fec_inner="5" system="0" modulation="1"/>
    </sat>
    </satellites>
    

    sat 它的元素 name

    这是我的代码: var satellitesData = fileData.find('sat[name='+satName+']');

    var satellitesData = $(fileData).find('sat[name='+satName+']');

    var satellitesData = fileData.find('sat[name='+satName+'] > transponder');

    var satellitesData = fileData.find('sat[name='+satName+']').innerHTML;

    1 回复  |  直到 6 年前
        1
  •  3
  •   CertainPerformance    6 年前

    name querySelector 而不是 .find 用于jquery或普通的javascript数组,但不用于javascript htmlelements)。

    const satName = "NSS 9/Yamal 300K (177.0W)";
    const satellites = document.querySelector('satellites');
    const satellitesData = satellites.querySelector('sat[name="' + satName + '"]');
    console.log(satellitesData);
    <satellites>
      <sat name="NSS 9/Yamal 300K (177.0W)" flags="0" position="-1770">
        <transponder frequency="3792000" symbol_rate="2048000" polarization="1" fec_inner="2" system="1" modulation="1" />
        <transponder frequency="3987000" symbol_rate="8950000" polarization="1" fec_inner="2" system="0" modulation="1" />
        <transponder frequency="3999000" symbol_rate="2960000" polarization="1" fec_inner="3" system="0" modulation="1" />
        <transponder frequency="4055000" symbol_rate="11000000" polarization="0" fec_inner="1" system="1" modulation="1" />
        <transponder frequency="4099000" symbol_rate="30000000" polarization="1" fec_inner="7" system="1" modulation="1" />
        <transponder frequency="4163000" symbol_rate="2644000" polarization="1" fec_inner="3" system="1" modulation="1" />
      </sat>
      <sat name="AMC 8/18 (139.0W)" flags="0" position="-1390">
        <transponder frequency="4056000" symbol_rate="13250000" polarization="0" fec_inner="3" system="0" modulation="1" />
      </sat>
      <sat name="AMC 10 (135.0W)" flags="0" position="-1350">
        <transponder frequency="3780000" symbol_rate="30000000" polarization="0" fec_inner="3" system="1" modulation="2" />
        <transponder frequency="3820000" symbol_rate="29270000" polarization="0" fec_inner="3" system="0" modulation="1" />
        <transponder frequency="4080000" symbol_rate="29270000" polarization="1" fec_inner="3" system="0" modulation="1" />
        <transponder frequency="4136000" symbol_rate="19510000" polarization="0" fec_inner="3" system="0" modulation="1" />
        <transponder frequency="4149000" symbol_rate="9760000" polarization="0" fec_inner="3" system="0" modulation="1" />
        <transponder frequency="4180000" symbol_rate="29270000" polarization="0" fec_inner="5" system="0" modulation="1" />
      </sat>
    </satellites>

    const satellitesData = satellites.querySelector(`sat[name="${satName}"]`);