


Detailed explanation of code cases for accessing XML documents by application name
一Requirement
ApplicationgetElementsByTagName Method to access the data in the XML document by name
Second analysis
Access the XML document by name
First apply ActiveX#. ##ObjectCreate a Microsoft parser instance, and then load the XML document into memory
Then use the getElementsByTagName() method to obtain thereference## of the number element, name element and object element. #, the return result is an array, each element in the array corresponds to an element in the XML document, and the order is the same. Finally get the value of the text contained in the corresponding element, and
StringThree Notes##Start counting from 0 in the subscript of JavaScript
.AttributeDescribes the need to access the text contained in the name element, rather than accessing the name element itself; the data attribute obtains the value of the node. Four codes
<?xml version="1.0" encoding="GB2312"?> <employes> <employe id='1' attendence='经理'> <number>1001</number> <name>程**</name> <object>PHP</object> <tel>84971547</tel> <address>长春市</address> <e_mail>cak**@sina.com</e_mail> </employe> <employe id='2' attendence='员工'> <number>1002</number> <name>龙**</name> <object>SQL</object> <tel>1234556</tel> <address>武汉市</address> <e_mail>ak**@sina.com</e_mail> </employe> </employes>HTML code
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>应用名称访问XML文档</title> </head> <script> function get_xml() { var xmldoc,employesNode,employeNode,peopleNode; //定义变量 var nameNode,titleNode,numberNode,displayText; //定义变量 xmldoc = new ActiveXObject("Microsoft.XMLDOM"); //创建Microsoft解析器实例 xmldoc.async = false; xmldoc.load("index.xml"); //载入指定的XML文档 numberNode=xmldoc.getElementsByTagName("number")[1]; //获取number元素的引用,访问员工的第2条信息 nameNode=xmldoc.getElementsByTagName("name")[1]; //获取name元素的引用 objectNode=xmldoc.getElementsByTagName("object")[1]; telNode=xmldoc.getElementsByTagName("tel")[1]; //实现字符串的拼接,输出XML文档中的数据 displayText="员工信息:"+numberNode.firstChild.data+','+nameNode.firstChild.data+', '+objectNode.firstChild.data+','+telNode.firstChild.data; div.innerHTML=displayText; //指定在ID标识为div的<div>标签中输出字符串displayText的信息 } </script> <body> <h1 id="应用名称访问XML文档">应用名称访问XML文档</h1> <!--应用onClick事件调用函数get_xml()--> <input type="button" value="获取XML中的指定数据" onClick="get_xml()"> <div id="div"></div> </body> </html>
Five running results
The above is the detailed content of Detailed explanation of code cases for accessing XML documents by application name. For more information, please follow other related articles on the PHP Chinese website!

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.

The steps to create an RSS document are as follows: 1. Write in XML format, with the root element, including the elements. 2. Add, etc. elements to describe channel information. 3. Add elements, each representing a content entry, including,,,,,,,,,,,. 4. Optionally add and elements to enrich the content. 5. Ensure the XML format is correct, use online tools to verify, optimize performance and keep content updated.

The core role of XML in RSS is to provide a standardized and flexible data format. 1. The structure and markup language characteristics of XML make it suitable for data exchange and storage. 2. RSS uses XML to create a standardized format to facilitate content sharing. 3. The application of XML in RSS includes elements that define feed content, such as title and release date. 4. Advantages include standardization and scalability, and challenges include document verbose and strict syntax requirements. 5. Best practices include validating XML validity, keeping it simple, using CDATA, and regularly updating.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function