使用 Javascript 获取 XML 节点值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16249605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:53:55  来源:igfitidea点击:

Getting XML nodevalue with Javascript

javascriptxmlajaxnodevalue

提问by Tuna Fish

I am trying to figure out how to get a node's value in Javascript. I've read a few tutorials but the examples they use are all much more complex than what I'm doing..

我想弄清楚如何在 Javascript 中获取节点的值。我已经阅读了一些教程,但他们使用的示例都比我正在做的要复杂得多。

Here's my Javascript

这是我的 Javascript

        if(xmlhttpp.readyState==4 && xmlhttpp.status==200){
            document.getElementById("ajax_status").innerHTML=xmlhttpp.responseXML.getElementsByTagName('status').nodeValue;
        }

And the XML is..

而 XML 是..

<?xml version='1.0' encoding='UTF-8'?>
<resp><fname>Kyla</fname>
<lname>Bonds</lname>
<addr>6916 S Elizabeth Street</addr>
<city>Chicago</city>
<street>IL</street>
<zip>60636</zip>
<phone></phone>
<email>[email protected]</email>
<status>Found user</status></resp>

How can I get "Found User" from this?

我怎样才能从中获得“找到的用户”?

回答by Musa

Try

尝试

xmlhttpp.responseXML.getElementsByTagName('status')[0].firstChild.nodeValue