Defining A Custom XML Element

The Dictionary class object can define an XML element when placed in an Elements collection for a supporting object. Normally, a programmer would simply use the AddElement method to add an XML element to the collection of a particular object. This sets the name of the element, and optionally, the content. However, adding attributes requires adding extra key/value pairs to the corresponding Dictionary object. The name and content of the element use two predefined keys that are required when building the element's CDF string. The predefined keys used to define the element are listed below.

Key Value Value Type
Tag This value becomes the name of the XML element. String. The string should comply with the XML specification on naming elements.
Content This value becomes the content of the element. String.

All other key value pairs become attribute and value pairs for the element.

A programmer must be careful not to overwrite the contents indexed under "tag" and "content," as they are reserved and may not be used as names for attributes in this case. When the element's CDF string is built, the value under "tag" always becomes the name of the element, and the value under "content" always becomes the content of the element. All other key/value pairs always become attribute and value pairs for the element.

Example

As an example, we will add the following XML element to a Channel object:

<THIS ATTRIB1=VAL1 ATTRIB2=VAL2>
This is some content
</THIS>

The following key/value pairs would define this element in a Dictionary object.

Key Value
Tag "THIS"
Content "This is some content"
"attrib1" "VAL1"
"attrib2" "VAL2"

Note   The keys "attrib1" and "attrib2" are shown in lowercase specifically. This is because the Dictionary object stores all keys in lower case internally. Thus, "ATTRIB1", "attrib1", and "AtTrIb1" all refer to the same key. The parent object converts the keys to upper case when it creates the CDF string for the element.

The code below demonstrates the process of defining the XML element above in VBScript by using the Channel object. Since the Dictionary class is not a bona fide COM class, we cannot directly create an instance. We must use the AddElement method to get started.

Set Element = Channel.AddElement("this","this is some content")
Element("attrib1")="VAL1"
Element("attrib2")="VAL2"

© 1997-1998 Microsoft Corporation. All rights reserved.