简体   繁体   English

如何使用Javascript搜索XML文档信息?

[英]How to search XML document info with Javascript?

I am making an account system and at the moment I am writing the code for a test to see if a (username, email, ext) is registered. 我正在创建一个帐户系统,此刻正在编写测试代码,以查看是否已注册(用户名,电子邮件,分机)。 But to do this I need Javascript to read the XML docs with the info. 但是要做到这一点,我需要Javascript来读取带有信息的XML文档。 How do you get Javascript to read the XML docs? 您如何获得Javascript来阅读XML文档? Here is an example XML doc. 这是一个XML文档示例。

    <?xml version="1.0"?>
    <user>
        <firstName>Bob</firstName>
        <lastName>Smith</lastName>
        <email>bob.smith@fakeEmail.com</email>
        <username>BobS.</username>
        <password>pizza</password>
    </user>

There are two real steps here. 这里有两个实际步骤。 I will use jquery for simplicity sake. 为了简单起见,我将使用jquery。

1.Get the XML resource: 1.获取XML资源:

AJAX: var xmlDoc = $.get('XMLURL').promise(function (xmlData){ //do step two }); AJAX:var xmlDoc = $ .get('XMLURL')。promise(function(xmlData){//执行第二步});

Embedded in HTML like in this question: Embedding XML in HTML 像这个问题一样嵌入到HTML中: 在HTML中嵌入XML

2.Once you have the DOM: 2.一旦有了DOM:

Use jquery: http://api.jquery.com/jQuery.parseXML/ 使用jquery: http : //api.jquery.com/jQuery.parseXML/

Or do it yourself: http://www.w3schools.com/xml/xml_parser.asp 或自己动手: http : //www.w3schools.com/xml/xml_parser.asp

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

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