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.
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".
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.
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".
- 上一篇：XML解析错误：未组织好 的解决办法