   
text
Is a member of:
|
DOMDocument
XMLDOMNode
XMLDOMAttribute
XMLDOMCDATASection
XMLDOMComment
XMLDOMDocumentFragment
XMLDOMDocumentType
XMLDOMElement
XMLDOMEntity
XMLDOMEntityReference
XMLDOMNotation
XMLDOMProcessingInstruction
XMLDOMText
XTLRuntime
|
Syntax
strValue = objXMLDOMNode.text
Remark
For writing the values to a Node, the text property is used. The text property normalizes white space, unless the DOMDocument has been specified to preserve the white space (see the preserveWhiteSpace property).
When reading the value of a Node, using the text property can lead to some strange behavior if your current Node has children.
Example
The following XML example explains what we meant by the previous comment.
<PEOPLE>
<PERSON id="1">
<NAME>Mark Wilson</NAME>
<ADDRESS>911 Somewhere Circle, Canberra, Australia</ADDRESS>
<TEL>(++612) 12345</TEL>
<FAX>(++612) 12345</FAX>
<EMAIL>markwilson@somewhere.com</EMAIL>
</PERSON>
....
</PEOPLE>
For the other properties, like the nodeType property, we explained how to get references to
CDATA sections, etc. However, if you are looking for the text of a Node and are not too concerned about interrogating whether the subchildren consist of
CDATA sections or entities, then just getting the text property will return the parsed data of your element.
In our example we have loaded our DOMDocument, which consists of our People2.xml file. We then get a reference to the
firstChild property (objNode = '<PERSON id="1">') of the documentElement property:
Dim objDOMDocument As DOMDocument
Dim objNode As IXMLDOMNode
Dim strText as String
Set objDOMDocument = New DOMDocument
objDOMDocument.async = False
objDOMDocument.resolveExternals = True
objDOMDocument.validateOnParse = True
objDOMDocument.Load "http://localhost/xmlcode/people2.xml"
Set objNode = objDOMDocument.documentElement.firstChild
strText = objNode.text
Our objNode has child Nodes; therefore, its text property returns the values of all its child Nodes. The string strText returns the following:
Mark Wilson 911 Somewhere Circle, Canberra, Australia (++612) 12345 (++612) 12345
markwilson@somewhere.com"
The value return has all the tags, and the less than (<) and greater than (>) signs have been removed, with a space inserted between each child for the current Node.    
This manuscript is an abridged version of a chapter
from the Manning
Publications book XML
Programming with VB and ASP. This chapter looks at the Microsoft DOM objects. NOTE: Most images have been removed to increase speed and many of the code comments have also been removed for presentation. Please purchase the book to enjoy the full experience of all the chapters with images and code comments!
|