jscript与vbscript 操作XML元素属性的代码_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)

时间: 2024-08-02 20:00:09

jscript与vbscript 操作XML元素属性的代码_XML示例的相关文章

php中操作xml文档程序代码

 代码如下 复制代码   /* <?xml version="1.0" encoding="UTF-8"?> <班级> <学生 number="101"> <名字>孙悟空</名字> <名字>孙行者</名字> <年龄>猴精猴精</年龄> <介绍></介绍> </学生> <学生 number="

asp.net C#操作xml文档实现代码

 代码如下 复制代码 XmlDocument xmldoc = new XmlDocument();             //在XML的文档的最头部加入XML的声明段落             XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");             xmldoc.AppendChild(xmlnode);             //创建根节点   

获取xml元素属性个数问题

问题描述 兄弟们:如果一条这样的数据:<datafd_id3="2009-03-1013:16:56"fd_id2="http://testwas.midea.com.cn/miptest/km/culture/doc/km_cul_doc_main/kmCulDocMain.do?method=viewCommPublic&fdId=92051009"fd_id1="济济一堂,共话机电科技发展新蓝图"id="1"

php simplexmlElement操作xml的命名空间实现代码

看了这个问题,第一个反应就是namespace的关系,但我从来没有使用simplexml操作过namespace,于是就翻开手册查了一下资料,问题并没有解决,最终是通过google解决了该问题. 提问题的朋友贴出了数据源,来自于:http://code.google.com/intl/zh-CN/apis/contacts/docs/3.0/developers_guide_protocol.html#retrieving_without_query,数据结构大致如下: 复制代码 代码如下: <

php simplexmlElement操作xml的命名空间实现代码_php技巧

看了这个问题,第一个反应就是namespace的关系,但我从来没有使用simplexml操作过namespace,于是就翻开手册查了一下资料,问题并没有解决,最终是通过google解决了该问题. 提问题的朋友贴出了数据源,来自于:http://code.google.com/intl/zh-CN/apis/contacts/docs/3.0/developers_guide_protocol.html#retrieving_without_query,数据结构大致如下: 复制代码 代码如下: <

请高手指点asp.net(C#)解析xml节点属性?代码如下:如何topic,这个节点属性解析出来,在线等…………

问题描述 demo.xml<?xmlversion="1.0"encoding="utf-8"?><notepad><topicname="nihao"a="23432"b="3243">主题</topic><content>内容内容</content></notepad>xpath.aspx<%@PageLangua

powerbuilder(pb)中 xml的应用一例_XML示例

示例文件如下(不贴DTD了,举简单例子说明一下) 复制代码 代码如下: <trans> <transdetail> <order><date/></order> <orderdetail><product/></orderdetail> <orderdetail><product/></orderdetail> </transdetail> <transde

读大数据量的XML文件的读取问题_XML示例

而如果使用XMLReader的话,不需要缓存,读取速度很快,但是如果要查询就不那么方便了,不支持XPath,只能通过Reader()方法前向循环.为了避免以上两种方法的缺点,想出以下方案: 1.先使用XMLReader将XML文件的内容读取到一个链表中. 2.查询的时候查询链表就可以了(可以在定义链表的类中定义查询函数,要查询的时候直接调用函数就可以了,非常方便). 结果证明:速度和查询效果都很好.

asp读取xml文件和记数_XML示例

复制代码 代码如下: if isnumeric(id)=false then exit sub strSourceFile = Server.MapPath(dataxml&"/Advertisement/"&id&"/adv.xml") Set objXML =Server.CreateObject("Microsoft.XMLDOM")  '创建一个XML对像  objXML.load(strSourceFile)