Results 1 to 2 of 2

Thread: XML and VB6.0

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    27

    XML and VB6.0

    I am just trying to get to grips with XML using the DOMDocument and related objects in Visual Basic 6.0

    I've managed to create an XML document based on a recordset returned from an Access database using ADO.

    I cycle thru the recordset adding the records using the various append methods and then call xmlDoc.Save. My xml document ends up in the form...

    <data>
    <record ID="1" LName="Hobson" FName="Graham"</record>
    <record ID="2" LName="Smith" FName="John"</record>
    </data>

    I have two questions: -

    1. How do I get the <?xml version="1.0"?> line to appear at the beginning of the file as it always is in the help file examples.

    2. When I open the file in IExplorer the layout is as above (OK). However when I open it in Notepad (for instance to edit directly) the file is not layed out like this but is one long textstream i.e.

    <data><record ID="1" LName="Hobson" Name="Graham"</record><record ID="2" LName="Smith" FName="John"</record></data>

    When I open other XML files in Notepad they have the same alyout as the IExplorer version. Why is this?

    If anyone can help I would be grateful. Thanks.

    PS The first example is indented at the record level but I don't think it displays correctly on here.

  2. #2
    Member
    Join Date
    Sep 2000
    Location
    Kentucky
    Posts
    56
    I got this code from the MSXML4.0 SDK.

    Question 1:
    VB Code:
    1. ' Create a processing instruction targeted for xml.
    2.     Set node = dom.createProcessingInstruction("xml", "version='1.0'")
    3.     dom.appendChild node
    4.     Set node = Nothing
    5.    
    6.     ' Create a processing instruction targeted for xml-stylesheet.
    7.     Set node = dom.createProcessingInstruction("xml-stylesheet", _
    8.                                 "type='text/xsl' href='test.xsl'")
    9.     dom.appendChild node
    10.     Set node = Nothing
    11.    
    12.     ' Create a comment for the document.
    13.     Set node = dom.createComment("sample xml file created using XML DOM object.")
    14.     dom.appendChild node
    15.     Set node = Nothing

    Question 2:
    VB Code:
    1. ' Insert a newline + tab.
    2.     root.appendChild dom.createTextNode(vbNewLine + vbTab)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width