• xml文档节点属性的访问


    <Product ProductSNO="35" ProductName="速度与激情2" />
    <Product ProductSNO="36" ProductName="大地雄心" />
    <Product ProductSNO="37" ProductName="木乃伊归来" />
    <Product ProductSNO="38" ProductName="落叶归根" />
    <Product ProductSNO="39" ProductName="太阳花" />
    <Product ProductSNO="40" ProductName="憨豆先生的大灾难" />
    <Product ProductSNO="41" ProductName="诺丁山" />
    <Product ProductSNO="42" ProductName="末世纪暴潮" />
    <Product ProductSNO="43" ProductName="星际传奇" />
    <Product ProductSNO="44" ProductName="小猪宝贝" />

    其中的ProductSNO和ProductName称为节点的属性,DOM解析的方法为
             var root = o.responseXML.documentElement;
                      
             var s = "<br>";
             for(var i=0;i<root.getElementsByTagName(Product ).length;i++)
             {
                 s = s + root.getElementsByTagName(Product )[i].attributes[0].text ;            
             }

    <Product>
      <ProductSNO>35</ProductSNO>
      <ProductName>速度与激情2</ProductName>
    </Product>
    <Product>
      <ProductSNO>36</ProductSNO>
      <ProductName>大地雄心</ProductName>
    </Product>
    <Product>
      <ProductSNO>37</ProductSNO>
      <ProductName>木乃伊归来</ProductName>
    </Product>
    <Product>
      <ProductSNO>38</ProductSNO>
      <ProductName>落叶归根</ProductName>
    </Product>
    <Product>
      <ProductSNO>39</ProductSNO>
      <ProductName>太阳花</ProductName>
    </Product>
    <Product>
      <ProductSNO>40</ProductSNO>
      <ProductName>憨豆先生的大灾难</ProductName>
    </Product>
    <Product>
      <ProductSNO>41</ProductSNO>
      <ProductName>诺丁山</ProductName>
    </Product>
    <Product>
      <ProductSNO>42</ProductSNO>
      <ProductName>末世纪暴潮</ProductName>
    </Product>
    <Product>
      <ProductSNO>43</ProductSNO>
      <ProductName>星际传奇</ProductName>
    </Product>
    <Product>
      <ProductSNO>44</ProductSNO>
      <ProductName>小猪宝贝</ProductName>
    </Product>

    其中ProductSNO和ProductName成为子节点,DOM解析的方法为
    var root = o.responseXML.documentElement;
                      
             var s = "<br>";
             for(var i=0;i<root.getElementsByTagName(Product ).length;i++)
             {
                 s = s + root.getElementsByTagName(Product )[i].childNodes[0].nodeValue;            
             }
  • 相关阅读:
    flutter-布局(水平和垂直)
    flutter-GridView(网格列表)
    flutter-ListView(列表组件)
    flutter-图片组件(Image)的使用
    flutter-container-容器
    flutter-hello flutter 并且修改字体
    nginx
    初步学习next.js-7-打包
    初步学习next.js-6-使用antd
    初步学习next.js-5-编写css样式和lazyloading
  • 原文地址:https://www.cnblogs.com/xp/p/1146938.html
Copyright © 2020-2023  润新知