XML
  Home arrow XML arrow Page 4 - Using MSXML3.0 with VB 6.0
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Using MSXML3.0 with VB 6.0
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 19
    2006-11-07

    Table of Contents:
  • Using MSXML3.0 with VB 6.0
  • MSXML Document30 Properties and Methods
  • Creating an XML Document using VB 6.0
  • Adding a child node to the student node
  • Manipulating the XML document

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using MSXML3.0 with VB 6.0 - Adding a child node to the student node


    (Page 4 of 5 )

    You will create a new element by creating an IXMLDOMElement, and you will add it to the appropriate Element (in this case the student element) using the appendChild () method as shown by the highlighted portion in the following snippet.

    Private Sub Command1_Click()
    Dim xmldoc As DOMDocument30
    Dim ProcInstr As IXMLDOMProcessingInstruction
    Dim rootElement As IXMLDOMElement
    Dim aElement As IXMLDOMElement
    Dim cElement As IXMLDOMElement
    Dim dElement As IXMLDOMElement
    'Creating DOM Document object
    Set xmldoc = New DOMDocument30
    'this adds the processing instruction
    'the first line in an XML document 
    Set ProcInstr = xmldoc.createProcessingInstruction("xml", 
    "version=""1.0""") xmldoc.appendChild ProcInstr 'Create the root element Set rootElement = xmldoc.createElement("wroot") Set xmldoc.documentElement = rootElement 'Creating comment node Set comElement = xmldoc.createComment("My students who took web
    programming") 'add the comment node after the root rootElement.appendChild comElement 'Create the node student Set aElement = xmldoc.createElement("student") 'add the student node to the root rootElement.appendChild aElement 'create a child element, 'name' for the student Set cElement = xmldoc.createElement("name") 'add a value for this node, 'Linda Jones' cElement.nodeTypedValue = "Linda Jones" 'cElement is child of aElement 'add the cElement as a child of aElement aElement.appendChild cElement 'Saving the xml document to c:testWebStudents.xml xmldoc.save "c:testWebStudents.xml " WebBrowser1.Navigate2 ("c:testWebStudents.xml") End Sub

    The output of this code as seen in the browser is shown in the following picture.

    Adding attributes to the student node

    Adding an attribute consists of declaring an object of the type IXMLAttribute. This is followed by creating this object using the CreateAttribute() method. Attributes are name value pairs; the name is assigned during creation. Next you use the attributes' text property to associate the name with a value. Finally associate this attribute with the element you want as shown in the following code listing. The highlighted code statements show the process.

    Private Sub Command1_Click()
    Dim xmldoc As DOMDocument30
    Dim ProcInstr As IXMLDOMProcessingInstruction
    Dim rootElement As IXMLDOMElement
    Dim aElement As IXMLDOMElement
    Dim cElement As IXMLDOMElement
    Dim dElement As IXMLDOMElement
    Dim att As IXMLDOMAttribute
    'Creating DOM Document object
    Set xmldoc = New DOMDocument30
    'this adds the processing instruction
    'the first line in an XML document 
    Set ProcInstr = xmldoc.createProcessingInstruction("xml",
    "version=""1.0""") xmldoc.appendChild ProcInstr 'Create the root element Set rootElement = xmldoc.createElement("wroot") Set xmldoc.documentElement = rootElement 'Creating comment node Set comElement = xmldoc.createComment("My students who took
    web programming") 'add the comment node after the root rootElement.appendChild comElement 'Create the node student Set aElement = xmldoc.createElement("student") 'add the student node to the root rootElement.appendChild aElement 'create a child element, 'name' for the student Set cElement = xmldoc.createElement("name") 'add a value for this node, 'Linda Jones' cElement.nodeTypedValue = "Linda Jones" 'cElement is child of aElement 'add the cElement as a child of aElement aElement.appendChild cElement 'append another child to the 'student' element '------------- Set dElement = xmldoc.createElement("legacySkill") dElement.nodeTypedValue = "Access, VB5.0" aElement.appendChild dElement '-------attributes--- '---create an attribute using the createAttribute() method '---at the same time set its name Set att = xmldoc.createAttribute("id") '---set the attributes 'text' property att.Text = "1" '--for the aElement, which is 'student' set a named '---attribute, it's name is att aElement.Attributes.setNamedItem att '---------------------- 'Saving the xml document to c:testWebStudents.xml xmldoc.save "c:testWebStudents.xml" WebBrowser1.Navigate2 ("c:testWebStudents.xml") End Sub

    When you execute the code by clicking the button, the form will be displayed as shown in the next picture. You may also notice that a second child to the student node has been added.

    In writing the code you must leverage the intellisense support to the maximum extent if you want to avoid errors. Make use of the drop-down cue you get while coding as shown.

    More XML Articles
    More By Jayaram Krishnaswamy


       · That being said, it is always good to have a few tools to read through the document,...
       · Excellent article, page 5 was exactly what I needed. Wish I had found this earlier...
     

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway