Create XML Using the MSXML Object Library

' This procedure creates XML document
' and saves it to disk.
' Requires msxml.dll (Go to Project --> References and
' and choose Microsoft XML version 2.0, or whatever the
' current version you have installed)
' The example given below will write the following XML
' documents.
'
' <Family>
'    <Member Relationship="Father">
'       <Name>Some Guy</Name>
'    </Member>
' </Family>
'
'but it should be clear how to modify the code
'to create your own documents

Private Sub Create_XML()
  
   Dim objDom As DOMDocument
   Dim objRootElem As IXMLDOMElement
   Dim objMemberElem As IXMLDOMElement
   Dim objMemberRel As IXMLDOMAttribute
   Dim objMemberName As IXMLDOMElement
  
   Set objDom = New DOMDocument
  
   ' Creates root element
   Set objRootElem = objDom.createElement("Family")
   objDom.appendChild objRootElem
  
   ' Creates Member element
   Set objMemberElem = objDom.createElement("Member")
   objRootElem.appendChild objMemberElem
  

<iframe id="I1_1404808061524" style="position: absolute; margin: 0px; width: 450px; top: -10000px; border-style: none;" name="I1_1404808061524" src="https://apis.google.com/_/+1/fastbutton?usegapi=1&amp;annotation=inline&amp;size=medium&amp;origin=http%3A%2F%2Fwww.freevbcode.com&amp;url=http%3A%2F%2Ffreevbcode.com%2FShowCode.asp%3FID%3D1919&amp;gsrc=3p&amp;hostiemode=8&amp;jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.zh_CN.Hj3WaNYFM6I.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAItRSTOjSJkhgaVGCGUWeMHhneeEEBh6ig#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&amp;id=I1_1404808061524&amp;parent=http%3A%2F%2Fwww.freevbcode.com&amp;pfname=&amp;rpctoken=4749925" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="100%" data-gapiattached="true"></iframe>
<?XML:NAMESPACE PREFIX = G ?>
Category:

ASP, HTML and XML

Type:

Snippets

Difficulty:

Beginning

Author:
Andrew Park

Version Compatibility: Visual Basic 6

More information:
This code shows you how to create simple xml document. Refer to comments for further details.

Instructions: Copy the declarations and code below and paste directly into your VB project.

 

------------------------------------------------------------

   ' Creates Attribute to the Member Element
   Set objMemberRel = objDom.createAttribute("Relationship")
   objMemberRel.nodeValue = "Father"
   objMemberElem.setAttributeNode objMemberRel
  
   ' Create element under Member element, and
   ' gives value "some guy"
   Set objMemberName = objDom.createElement("Name")
   objMemberElem.appendChild objMemberName
   objMemberName.Text = "Some Guy"

   ' Saves XML data to disk.
   objDom.save ("c:\temp\andrew.xml")
End Sub

 

--------------------------------------------

 

copied from  http://www.freevbcode.com/ShowCode.asp?ID=1919 

你可能感兴趣的:(library)