


Detailed code explanation for online editing of XML documents using XSL and ASP
This article explains the method of online editing of XML document data through a detailed example. Since Netscape's support for XML is relatively weak, to achieve cross-platform data exchange, data processing must be performed on the server side. To edit an XML document, the first thing to do is how to extract and display the data to visitors. XSL provides a good solution for us to display XML files. The following example uses an XSL style sheet to display an XML document for users to edit, and then submits the edited data to the server, where the data is processed on the server sideUpdate. Here we use ASP (Active Server Pages) to complete our tasks.
First of all , load the XML document we want to edit, and using Microsoft DocumentObjectModel (Microsoft XMLDOM Object) and XSL, the XML document can be processed on the server side Convert it into HTML file content that can be displayed on the client. Let's take a look at what the XML and XSL files we use look like.
XML file: userdata.xml
<?xml version="1.0" encoding="gb2312"?> <用户资料> <field id="姓名" taborder="1"> <field_value>孟子</field_value> </field> <field id="性别" taborder="2"> <field_value>男</field_value> </field> <field id="单位名称" taborder="3"> <field_value>中国网络技术发展公司北京分公司</field_value> </field> <field id="详细地址" taborder="4"> <field_value>北京市嘉里中心102层</field_value> </field> <field id="电话" taborder="5"> <field_value>1391139136*</field_value> </field> <field id="电子邮件" taborder="6"> <field_value>amxh@21cn.com</field_value> </field> </用户资料> XSL文件:userdata.xsl <?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <body> <form method="post" action="Edituserdata.asp"> <h1 id="用户资料编辑">用户资料编辑:</h1> <table border="1" cellpadding="2"> <xsl:for-each select="用户资料/field"> <tr> <td> <xsl:value-of select="@id"/> </td> <td> <input type="text"> <xsl:attribute name="id"> <xsl:value-of select="@id" /> </xsl:attribute> <xsl:attribute name="name"><xsl:value-of select="@id" /> </xsl:attribute> <xsl:attribute name="value"> <xsl:value-of select="field_value" /> </xsl:attribute></input> </td> </tr> </xsl:for-each> </table> <br /> <input type="submit" id="btnSubmit" name="btnSubmit" value="完成编辑" /> </form> </body> </html> </xsl:template> </xsl:stylesheet>
XSL file usage. The XSL: for-each element is used to traverse the entire XML file. The "id" attribute of each "field" element in the XML file and the "id" of the text input box of the HTML form " and "name" want to correspond. In this way, the text input box of the HTML form displays the element value of the XML file. This file is responsible for converting the XML document on the server side so that it can be displayed on various browsers.
The following is the key program, which implements the function of opening and updating XML documents, and determines whether to update based on whether the form is submitted. It contains two functions, loadXMLFile, which is responsible for loading and converting the XML file to be displayed. ;The updateXML function is responsible for updating the XML file.
The Edituserdata.asp program is as follows:
<% '----------------------------------------------------------- '定义函数 loadXMLFile(),接收二个参数: 'strXMLFile - XML 文件的路径和文件名字 'strXSLFilee - XSL 文件的路径和文件名字 '----------------------------------------------------------- Function loadXMLFile(strXMLFile, strXSLFile) 'Declare local variables Dim objXML Dim objXSL '实例化 XMLDOM 对象,以便载入 XML 文件。 set objXML = Server.CreateObject("Microsoft.XMLDOM") '关掉文件异步载入模式。 objXML.async = false '载入 XML 文件! objXML.load(strXMLFile) '实例化 XMLDOM 对象,以便载入 XSL 文件。 set objXSL = Server.CreateObject("Microsoft.XMLDOM") '关掉文件异步载入模式。 objXSL.async = false '载入 XSL 文件! objXSL.load(strXSLFile) '利用 XMLDOM 的 transformNode 方法,把 XSL 样式表应用到 XML 文档,然后输出到客户端。 Response.Write(objXML.transformNode(objXSL)) End Function '------------------------------------------------------------------ '函数 updateXML() 接收一个参数:strXMLFile - XML 文件的路径和文件名。 '------------------------------------------------------------------ Function updateXML(strXMLFile) '声明局部变量。 Dim objDom Dim objRoot Dim objField Dim x '实例化 XMLDOM 对象。 set objDOM = Server.CreateObject("Microsoft.XMLDOM") '关掉文件异步载入模式。 objDOM.async = false '载入 XML 文件。 objDOM.load strXMLFile '设定根元素。 Set objRoot = objDom.documentElement '遍历 FORM 集合,并把提交的数据写入 XML 文件。 For x = 1 to Request.Form.Count '检查提交的数据是否包含按钮。如果是,忽略此数据。 If instr(1,Request.Form.Key(x),"btn") = 0 Then '按照 XSL 查询模式,建立 objField 变量,把表单的元素对应到 XML 文档里的相应元素[field_value]。 Set objField = objRoot.selectSingleNode("field[@id='" & Request.Form.Key(x) & "']/field_value") '把表单提交的数据和 XML 文档里的节点值对应起来。 objField.Text = Request.Form(x) End If Next '保存编辑过的 XML 文件。 objDom.save strXMLFile '释放所有对对象的引用。 Set objDom = Nothing Set objRoot = Nothing Set objField = Nothing '调用 loadXMLFile 函数,把新编辑后的 XML 文件用 updateduserdata.xsl 样式单显示到客户端。 loadXMLFile strXMLFile,server.MapPath("updateduserdata.xsl") End Function '检查表单是否成功提交,如提交,更新 XML 文件;否则,转到编辑状态。 If Request.Form("btnSubmit") = "" Then loadXMLFile server.MapPath("userdata.xml"),server.MapPath("userdata.xsl") Else updateXML server.MapPath("userdata.xml") End If %>
When the form is submitted successfully, we use updateduserdata.xsl to display the data we just edited. ##updateduserdata.xsl is as follows:
<?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <body> <h1 id="更新后的用户资料如下">更新后的用户资料如下:</h1> <table border="1" cellpadding="2"> <xsl:for-each select="用户资料/field"> <tr> <td> <xsl:value-of select="@id" /> </td> <td> <xsl:value-of select="field_value" /> </td> </tr> </xsl:for-each> </table> <form> <input type="button" value="返回" onclick="history.go(-1)" /> </form> </body> </html> </xsl:template> </xsl:stylesheet>
The above is the detailed content of Detailed code explanation for online editing of XML documents using XSL and ASP. For more information, please follow other related articles on the PHP Chinese website!

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing

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.


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

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

Zend Studio 13.0.1
Powerful PHP integrated development environment