Ajax traversal of xml documents
This document describes how to use ajax to traverse xml documents. Share it with you for your reference. The specific analysis is as follows:
The XMLHttpRequest object provides two attributes that can be used to access server responses. The first property responseText provides the response as a string, and the second property responseXML provides the response as an XML object. Some simple use cases are suitable for obtaining responses by simple text, such as displaying the response in the warning box, or the response is just a word indicating success or failure.
In the preceding <ajax summary> example, the server response is obtained from the XMLHttpRequest object, and the response is obtained as text using the responseText attribute of the XMLHttpRequest object.
This time, we use the responseXML attribute of the XMLHttpRequest object to obtain the result as an XML document. In this way, we can use the W3C DOM method to traverse XML documents. (I have mentioned DOM more or less in the previous article, but I will not repeat it here)
OK. The following is an example.
First, the XML document code (parseXML. xml) is as follows:
ParseXML. xml is as follows:
<?xml version="1.0" encoding="UTF-8"?><states><north><state>Minnesota</state><state>Iowa</state><state>North Dakota</state></north><south><state>Texas</state><state>Oklahoma</state><state>Louisiana</state></south><east><state>New York</state><state>North Carolina</state><state>Massachusetts</state></east><west><state>California</state><state>Oregon</state><state>Nevada</state></west></states>
MyJsp. jsp is as follows:
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
I hope this article will help you with Ajax programming.