【问题标题】:how to get all attributes of node in certain namespace xml javascript如何在某些命名空间xml javascript中获取节点的所有属性
【发布时间】:2013-04-20 04:07:29
【问题描述】:

我有一个来自 xml 文档的节点。它具有来自多个名称空间的多个属性。我想从 fo 命名空间中找到所有属性。如何才能做到这一点?例如从以下我想获得以 fo 开头的所有属性:

<thingy fo:line-height="200%" fo:blah="blah" gh:sdf="sdfdfer">
blah
</thingy>

【问题讨论】:

    标签: javascript xml namespaces xml-namespaces


    【解决方案1】:
    var tag = document.getElementsByTagName('thingy')[0];
    var attr = tag.attributes;
    for(var i=0;i<attr.length;i++)
    {
        if(attr.item(i).nodeName.search('fo:') == 0)
        {
            alert(attr.item(i).nodeName);
            alert(attr.item(i).nodeValue);
        }
    }
    

    Working JS Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-03
      • 1970-01-01
      • 1970-01-01
      • 2019-02-28
      • 2016-05-30
      • 1970-01-01
      相关资源
      最近更新 更多