Home > Web Front-end > JS Tutorial > body text

js implements reading xml file content

零到壹度
Release: 2018-03-24 13:22:12
Original
5458 people have browsed it

This time I will bring you js implementation to read the content of xml files, mainly in the form of code. The following is a practical case, let's take a look.

The html code is as follows

<html>

<body>
<h1>W3School.com.cn Internal Note</h1>
<p>
<b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</p>

<script type="text/javascript">
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.open("GET","/example/xmle/note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script>

</body>
</html>
Copy after login

XML file content

<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- Copyright w3school.com.cn -->
-<note>
Copy after login
 	<to>George</to>
Copy after login
	<from>John</from>
Copy after login
	<heading>Reminder</heading>
Copy after login
 	<body>Don&#39;t forget the meeting!</body>
Copy after login
</note>
Copy after login

Display results:

Related recommendations:

Simple jS to read XML data

Js reads xml and loads it into the page

Parse the xml file in html (javascript reading)

The above is the detailed content of js implements reading xml file content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!