javascript - jQuery 查找对 xml 标记名使用通配符?

标签 javascript jquery html xml regex

大家下午好

我试图找到所有包含特定单词的 xml 标记 - 即使用通配符。

xml 是这样使用的:

xml = $('<elements>' + $('#form_template').val() + '</elements>');

#form_template 中包含 xml 内容的位置。 然后我想在整个 xml 树中搜索以单词 item 开头的标记名。 我试过 xml.match(/item_[0-9]+/) 但返回的 match 不是一个函数。

任何线索如何在整个 xml 中搜索包含项目的标签?

问候,

编辑:代码示例 这用于创建 zend 表单。 html 与示例无关。

<QUESTION1>
<type>MultiCheckbox</type>
<options>
<class>rulem1 type-1 standard</class>
<label>Fabs and Equipments</label>
<multioptions>
<item-separate_equipments>Separate Equipments</item-separate_equipments>
<item-lasers>Lasers</item-lasers>
<item-metrology>Metrology / Inspection</item-metrology>
<item-turnkey>Turnkey Lines</item-turnkey>
<item-factory>Factory Design</item-factory>
</multioptions>
</options>
</QUESTION1>
<QUESTION2>
<type>MultiCheckbox</type>
<options>
<class>rulem1 type-1 standard</class>
<label>Material and Components</label>
<multioptions>
<item-backsheets>Backsheets</item-backsheets>
<item-raw_materials>Raw Materials</item-raw_materials>
<item-auxiliary>Auxiliary Materials</item-auxiliary>
<item-cell_coating>Coating</item-cell_coating>
<item-pastes>Pastes / Metallisation</item-pastes>
<item-tf>TF Gas</item-tf>
<item-foils>Foils</item-foils>
<item-encapsulation>Encapsulation</item-encapsulation>
<item-aluminium>Aluminium</item-aluminium>
<item-junction>Junction Box and Connection Systems</item-junction>
<item-materials_others>Others</item-materials_others>
</multioptions>
</options>
</QUESTION2>

最佳答案

您应该能够使用 .find(*) 递归查找所有标签,然后自己过滤它们,例如:

var res = xml.find('*').filter(function() {
    return this.nodeName.match(/item_[0-9]+/i);
});

关于javascript - jQuery 查找对 xml 标记名使用通配符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10621431/

相关文章:

javascript - 在 .on() 点击事件中附加后选择器不起作用

javascript - "return false"在某些浏览器中被忽略,因为链接使用 JavaScript 动态添加到 DOM

javascript - 在 jQuery weekcalendar 插件中为事件设置不同的背景颜色

javascript - 如何确保扩展类必须在 TypeScript 中设置属性值?

jquery - 如何自定义 Highcharts 的十字准线

jquery - CSS 和 jQuery slider 高度/定位问题

javascript - 声明对象的最佳方式是什么?

javascript - 如何从另一个javascript调用一个javascript函数?

jQuery 插件 : Colorpicker

html - 字体 Arial 在 Chrome 和 Firefox 中的结果不同