Parse XML files using Ajax and present them using dom

Source: Internet
Author: User

Yesterday, I learned how to parse XML files using Ajax. At the beginning, I used ajax to parse all the files contained in an XML file with a simple return time and put them under the IIS server. The files can be parsed normally after being accessed through a browser. At that time, I felt that Using ajax to parse XML files was not difficult! However, when I try to parse a more complex BBC. xml fileProgramEspecially when debugging, you have encountered unexpected difficulties and made many mistakes! Before writing a program, I thought clearly. To use ajax to successfully parse an XML file, there are three steps: first, create an asynchronous request to obtain the XML file on the server; second, how to parse the XML file; the third is to use Dom to present the data of the XML file obtained by second parsing. when I write a program based on my own thoughts and put it under IIS, I found countrynodes [I] During Firefox access, later I found out that I confused htmldom and xmldom, xmldoc. getelementsbytagname ("country") is written as document. getelementsbytagname ("country "). And I didn't even notice the BBC before programming. some text nodes under the country node of the XML file are empty, which leads to my unified firstnode. when nodevalue obtains the value of a text node, firebug always reports that the firstnode cannot be found.

many errors have also been made during the programming process, such as making a mistake in the number of nodes that have passed through the loop, an equal sign is added, leading to an error where the object is empty during multiple cycles. When creating an object, do not check whether the object exists. However, there are still a lot of gains in this process. Under the guidance of Mr. Tian, he learned to use Dom to parse and present data, such as using createelement (), createtextnode (), and appendchild () several common and useful methods. In addition, some experience has been learned during program debugging, such as using alert () to output variable values, whether the local debugging function Code works in this program for debugging. In addition, I also learned how to submit code reusability and program scalability, that is, to write code with the same function as a function with parameters, and then put it where necessary, input different parameters for calling. In addition, some painful lessons need to be learned during function calling, such as mixing variable names and strings, and using table to present data without the label. You must pay more attention to these small details when writing future programs! It seems that more hands-on work will be required in the future!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.