Results 1 to 5 of 5

Thread: [RESOLVED] XML Data Types and VB6

  1. #1

    Thread Starter
    Addicted Member thedoc1's Avatar
    Join Date
    Jan 2002
    Location
    Scenic Tonawanda, NY
    Posts
    143

    Resolved [RESOLVED] XML Data Types and VB6

    Hello,

    I am creating an XML file and I need to have data types defined in the section.

    Here is my code. How do I set datatypes for the XML File?

    Code:
        Dim xmlDoc As MSXML2.DOMDocument
        Dim xmlProcess As MSXML2.IXMLDOMProcessingInstruction
        Dim xmlObjSubData As IXMLDOMNode
        Dim xmlObjCycle As IXMLDOMNode
        Dim xmlObjCU As IXMLDOMNode
        Dim xmlObjDetails As IXMLDOMNode
        Dim lstrXMLFile As String
        
        Set xmlDoc = New MSXML2.DOMDocument
        
        lstrXMLFile = myxmlfile.xml
    
        If Dir(lstrXMLFile) <> "" Then
            Call KillFile(lstrXMLFile)   'this kills the file to start over....
        End If
        
        Set xmlProcess = xmlDoc.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8'")
        xmlDoc.appendChild xmlProcess
        
        'create root node
        Set xmlObjSubData = xmlDoc.createElement("SubmissionData")
        xmlDoc.appendChild xmlObjSubData
        xmlObjSubData.appendChild xmlObjSubData.ownerDocument.createTextNode(vbCrLf + Space$(5))
        
        Set xmlObjCycle = xmlDoc.createElement("Cycle")
        xmlObjSubData.appendChild xmlObjCycle
        xmlObjCycle.appendChild xmlObjCycle.ownerDocument.createTextNode(vbCrLf + Space$(10))
        
        Set xmlObjDetails = xmlDoc.createElement("Month")
        xmlObjDetails.text = Left$(Parm5300.mstrCycleDate, 2)
        xmlObjDetails.dataType = "string"
        xmlObjCycle.appendChild xmlObjDetails
        xmlObjCycle.appendChild xmlObjCycle.ownerDocument.createTextNode(vbCrLf + Space$(10))
        
        Set xmlObjDetails = xmlDoc.createElement("Year")
        xmlObjDetails.text = Right$(Parm5300.mstrCycleDate, 4)
        xmlObjDetails.dataType = "String"
        xmlObjCycle.appendChild xmlObjDetails
        xmlObjCycle.appendChild xmlObjCycle.ownerDocument.createTextNode(vbCrLf + Space$(5))
        
        Set xmlObjCycle = Nothing   'not sure how to end the cycle...
    Any help would be appreciated.

    Thanks
    Dave
    Thanks

    Doc

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: XML Data Types and VB6

    not sure what you mean... can you post an example of what you're looking for?

    EDIT - never mind, I see the highlighted code there... but I'm still not sure what you mean exactly... xml is essentially type-less... you have nodes. Nodes have values. You have attributes, attributes have values. they are what they are.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: XML Data Types and VB6

    Here's something I happen to be working on. It's a fragment at this point but it works as far as it has been completed and has an example of what I think you want:
    Code:
    Public Property Get XML() As String
        Dim DOM As MSXML2.DOMDocument40
        Dim ATTR As MSXML2.IXMLDOMAttribute
        
        Set DOM = New MSXML2.DOMDocument40
        With DOM.appendChild(DOM.createElement("onlinemq"))
            With .appendChild(DOM.createElement("header"))
                With .appendChild(DOM.createElement("version"))
                    .Text = header.version
                End With
                With .appendChild(DOM.createElement("created_at"))
                    Set ATTR = DOM.createAttribute("type")
                    ATTR.Value = "datetime"
                    .Attributes.setNamedItem ATTR
                    .Text = header.created_at.XSDString
                End With
                With .appendChild(DOM.createElement("action"))
                    .Text = header.action
                End With
            End With
        End With
        XML = DOM.XML
    End Property

  4. #4

    Thread Starter
    Addicted Member thedoc1's Avatar
    Join Date
    Jan 2002
    Location
    Scenic Tonawanda, NY
    Posts
    143

    Re: XML Data Types and VB6

    I think what I am looking at is creating attributes for the type fields.

    Does that help?

    Dave
    Thanks

    Doc

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: XML Data Types and VB6

    The sample code I listed above results in:
    Code:
    <onlinemq>
    <header>
    <version>1.0</version>
    <created_at type="datetime">2009-08-26T11:43:29-04:00</created_at>
    <action></action>
    </header>
    </onlinemq>
    Are you sure this wasn't what you were after?

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