次の方法で共有


Setting a DOMDocument Object as MXXMLWriter Output

 

The following code shows how to set the DOMDocument object as MXXMLWriter output and how to get the DOMDocument output using DOMDocument methods.

Setting Output

The following code shows how to set writer output as a DOMDocument object.

Private Sub Command1_Click()
    'Create the DOMDocument object.
    Dim xmlDoc As New Msxml2.DOMDocument30
    'Create an MXXMLWriter object.
    Dim wrt As New MXXMLWriter30
    'Reference the ContentHandler interface.
    Dim cnth As IVBSAXContentHandler

    'Set the writer as the content handler.
    Set cnth = wrt
    'Set the writer output to the xmlDoc object.
    wrt.output = xmlDoc

Getting Output

You can read the document at any time after the startDocument event is called. However, you cannot modify the document until after the endDocument event is called. The following code shows DOMDocument methods called on the xmlDoc object after the endElement method is called.

cnth.endDocument
     
    'Displays the author's name in a message box.
    Set objNodeList = xmlDoc.getElementsByTagName("author")
    MsgBox objNodeList.Item(0).Text

See Also

SAX to DOM Implementation Notes
MXXMLWriter CoClass
output Property
IXMLDOMDocument-DOMDocument