简体   繁体   English

如何使用JavaScript测试xml中是否存在特定标记名

[英]How to test if there is a specific tagname in xml using javascript

I want to check whether there is a specific tagname in an xml file, using javascript. 我想使用JavaScript检查xml文件中是否有特定的标记名。 pseudocode: 伪代码:

if (there_is_a_tag_name_called_<picture>)
{ variable=1;}
else
{variable=0;}

note: the if( "tagname.length>0") wont work.... 注意: if( "tagname.length>0")无法工作。

how can I do it? 我该怎么做?

I think you can use this 我想你可以用这个

if(node.getElementsByTagName("picture").length > 0){ 
variable=1;
 }
else
{variable=0;}

I am unable to past html content, Hence i am pasting my code as an image 我无法粘贴html内容,因此我将代码粘贴为图片

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM