首页 后端开发 XML/RSS教程 分享一个jscript与vbscript操作XML元素属性的方法

分享一个jscript与vbscript操作XML元素属性的方法

Apr 26, 2017 pm 01:57 PM
jscript vbscript xml操作

jscript与vbscript 操作XML元素属性的代码,需要的朋友可以参考下。

Although attributes belong to a particular element, they are not considered child nodes of element nodes. Instead, they behave more like properties of IXMLDOMElement. 
Most of the methods for working with attributes come from IXMLDOMElement. Attributes can be manipulated in the following ways. 
Directly, through the getAttribute and setAttribute methods of IXMLDOMElement. 
As named IXMLDOMAttribute nodes, with getAttributeNode and setAttributeNode. 
As a set of nodes accessible through the attributes property and returned as an IXMLNamedNodeMap. 
Examples 
JScript 
The following JScript example creates a new document containing a <memo> element, and then creates an attribute named author with a value of "Pat Coleman".
登录后复制

代码如下:

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); var rootElement=xmlDoc.createElement("memo"); rootElement.setAttribute("author", "Pat Coleman"); xmlDoc.appendChild(rootElement); 
VBScript
登录后复制

代码如下:

Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0") Set rootElement=xmlDoc.createElement("memo") rootElement.setAttribute("author", "Pat Coleman") xmlDoc.appendChild(rootElement) 
If you prefer to work with attribute nodes, you can create the attribute, and then create a text node to store its value. Attribute nodes can only contain text nodes and entity reference nodes. (If you need to create an attribute containing an entity reference, you must use this approach.) Working with attribute nodes requires using the DOMDocument object to create attribute and text (and entity reference, if necessary) nodes before assigning the nodes to the element. JScript The following JScript code uses this approach to perform the same work as the preceding examples, creating a <memo> element with an author attribute holding the value "Pat Coleman".
登录后复制

代码如下:

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0"); 
var rootElement=xmlDoc.createElement("memo"); 
var memoAttribute=xmlDoc.createAttribute("author"); 
var memoAttributeText=xmlDoc.createTextNode("Pat Coleman"); 
memoAttribute.appendChild(memoAttributeText); 
rootElement.setAttributeNode(memoAttribute); 
xmlDoc.appendChild(rootElement);
登录后复制

VBScript

代码如下:

Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0") 
Set rootElement=xmlDoc.createElement("memo") 
Set memoAttribute=xmlDoc.createAttribute("author") 
Set memoAttributeText=xmlDoc.createTextNode("Pat Coleman") 
memoAttribute.appendChild(memoAttributeText) 
rootElement.setAttributeNode(memoAttribute) 
xmlDoc.appendChild(rootElement)
登录后复制

以上是分享一个jscript与vbscript操作XML元素属性的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

如何使用RSS feed进行新闻汇总和内容策划? 如何使用RSS feed进行新闻汇总和内容策划? Mar 10, 2025 pm 03:47 PM

本文解释了如何使用RSS feed进行有效的新闻汇总和内容策划。 它详细介绍了使用RSS读取器(例如Feedly和Inoreader),组织供稿以及为目标内容的利用功能的订阅供稿。 利益

如何将ATOM发布协议用于Web内容管理? 如何将ATOM发布协议用于Web内容管理? Mar 10, 2025 pm 05:48 PM

本文解释了用于Web内容管理的原子出版协议(ATOMPUB)。 它使用HTTP方法(获取,发布,PUT,删除)详细介绍了用于内容创建,检索,更新和删除的原子格式。 本文还讨论了Atompub

如何使用RSS实施内容联合? 如何使用RSS实施内容联合? Mar 10, 2025 pm 03:41 PM

本文详细介绍了使用RSS提要实施内容联合的内容。 它涵盖创建RSS提要,识别目标网站,提交提要以及监视效率。 诸如有限控制和丰富媒体支持之类的挑战也是铁饼

手机XML转PDF,转换速度快吗? 手机XML转PDF,转换速度快吗? Apr 02, 2025 pm 10:09 PM

手机XML转PDF的速度取决于以下因素:XML结构的复杂性手机硬件配置转换方法(库、算法)代码质量优化手段(选择高效库、优化算法、缓存数据、利用多线程)总体而言,没有绝对的答案,需要根据具体情况进行优化。

如何集成XML和语义Web技术? 如何集成XML和语义Web技术? Mar 10, 2025 pm 05:50 PM

本文探讨了集成XML和语义网络技术。 核心问题是将XML的结构化数据映射到RDF三元组,以进行语义互操作性。 最佳实践涉及本体定义,战略映射方法,仔细的ATT

如何将XML用于医疗保健/财务/等的数据互操作性? 如何将XML用于医疗保健/财务/等的数据互操作性? Mar 10, 2025 pm 05:50 PM

本文使用XML详细介绍了数据互操作性,重点是医疗保健和金融。 它涵盖了模式定义,XML文档创建,数据转换,解析和交换机制。钥匙XML标准(HL7,DICOM,FinML,ISO 20022)

如何保护RSS提要,以防止未经授权的访问? 如何保护RSS提要,以防止未经授权的访问? Mar 10, 2025 pm 03:42 PM

本文详细介绍了针对未经授权访问的RSS供给。 它检查了各种方法,包括HTTP身份验证,具有速率限制的API密钥,HTTPS和内容混淆(灰心)。 最佳实践涉及IP限制,转换

如何为我的域创建自定义XML词汇? 如何为我的域创建自定义XML词汇? Mar 10, 2025 pm 05:48 PM

本文详细介绍了为数据一致性创建自定义XML词汇(schemas)。 它涵盖定义范围,识别实体和属性,设计XML结构,选择模式语言(XSD或放松NG),模式开发,测试

See all articles