dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: XML in VB6 Help

Hybrid View

  1. #1
    Join Date
    Nov 2010
    Posts
    1

    Exclamation XML in VB6 Help

    Hello All,

    I browse this forum often for a lot of help and it does just that, helps a lot. In any case, I have been looking for an answer to this for awhile and cannot find it.

    To begin, let me state what I am trying to do. I have a complex database system for POS. It relies on a number of DLLs to interact with windows and one of them is to print receipts. Recently, we have had to add some boxes to interact with the receipts printed. These boxes only read in XML. The company designing the boxes were nice enough to give us the XML Data Structure it reads:
    Code:
    <reqMEV>
          <trans 
                   noRef="XXX"
                   noVersion="XXX"
                   <doc>
                          <texte><!CDATA[
                                        ]]>
                           </texte>
                    </doc>
            <donneesTrans
                                 mvAtGht="XXXX"
                                 mvAtPht="XXXX" />
            </trans>
    </reqMEV>
    That is just a small snippet of the XML Structure given. The problem is that I have never seen that type of structure before and I am lost with it. I have tried a bunch of things in the DLL (cls and vbp taken apart) and none work.

    What I am asking bascially is where do I start? I have a couple ideas in VB6 code:

    strXML(0) = "<reqMEV>"
    strXML(1) = "<trans noRef=" & Chr(34) &

    Yadda Yadda. I load that as an XML and make reference to MSXML v3.0 and nothing works.

    I hope I am making some sense here as I am banging my head against a wall.

    Any help is greatly appreciated and if anyone wants a donation for their assistance I am willing.

    Thanks!

  2. #2
    Join Date
    May 2007
    Posts
    18
    Hi taros,

    I have had to deal with unusual and complex xml files in the past.

    A very useful program I found for navigating XML is a program called XML marker, it's freely available off the web.

    This helped me understand how the XML data was organised in the file.

    In general you have <Object> followed by associated data and terminated with </Object>
    You can nest the data, and objects, within the first object, i.e.
    trans is a child object of reqMEV and doc is a child object of trans.

    Hope it helps,
    Vulcon.
    Smile, And the whole world ...
    will want to know what your planning

  3. #3
    Join Date
    Nov 2010
    Posts
    1
    Hi vulcon,

    Thanks for informing me about that software. I tried it out and it does lay it out nicely for me to view (as the way I have been viewing it is very hard on the eyes).

    I am still unsure about the syntax to use for VB6. It has to be passed as a string and I have been trying to use the DOMDocument and create the Child and Element aspects, but I don't know the syntax to use when dealing with so many attributes inside of one element.

    Any idea with that?

    Thanks again!

  4. #4
    Join Date
    May 2007
    Posts
    18
    Hi,

    I'm inserting a function that I use to extract information from an line of an xml file.

    The idea of this was that I would carry out different actions depending on whether the information meant moving up the xml tree, down the xml tree or stationary and having or not having data.

    This function uses a very basic class used as a data holder, called cItem.

    You can structure your code around the returned data holder.

    The Class
    Code:
    ' This is the basic class holder for all parameters
    Public name As String '........ Parameter Name
    Public value As String '....... Parameter Value
    Public control As String '..... Multi-purpose Control field for internal workings
    Public index As Double '....... Used for quick reference when stored in an array
    The Function

    Code:
    Function extract(xmlLine As String) As cItem
    'This function extracts the details from the line and returns the values
    'Index Status defines type
    '   0 : Parameter and value     <ObjName>ObjValue</ObjName>
    '   1 : Named Type              <ObjName id="ObjValue">
    '   2 : Start Of Object         <ObjName>
    '   3 : Termination             <ObjName/>
    '   4 : Termination             </ObjName>
    
    Dim lineData As cItem
    Dim posInt As Integer, posEnd As Integer, field As String
    Dim xmlLine As String
    
    Set lineData = New cItem
    
    If Left(xmlLine, 1) = "<" Then
        
        '---------------------------------------------- Check for ignore information
        
        'Remove the leading bracket
        xmlLine = Right(xmlLine, Len(xmlLine) - 1)
        
        
        '-------------------------------------------- Check for Object Start
        If InStr(1, xmlLine, " id=") Then
            'Set the control field
            lineData.control = "Up"
            lineData.index = 1
            
            'Extract the control
            If InStr(1, xmlLine, ":") Then
                posInt = InStr(1, xmlLine, ":")
                xmlLine = Right(xmlLine, Len(xmlLine) - posInt)
            End If
            
            'Extract the type
            posInt = InStr(1, xmlLine, " id=")
            field = Trim(Left(xmlLine, posInt))
            lineData.name = field
            
            'Extract the name
            posInt = posInt + 5
            posEnd = InStr(posInt, xmlLine, Chr(34))
            If posEnd > posInt Then
                field = Trim(Mid(xmlLine, posInt, posEnd - posInt))
                lineData.value = field
            End If
            
        Else
            If Left(xmlLine, 1) = "/" Then
            
                'Extract the control. Need to keep here to prevent missing when removing control before :
                If InStr(1, xmlLine, ":") Then
                    posInt = InStr(1, xmlLine, ":")
                    xmlLine = Right(xmlLine, Len(xmlLine) - posInt)
                End If
            
                'Extract the type
                posInt = InStr(1, xmlLine, ">")
                field = Trim(Left(xmlLine, posInt - 1))
                lineData.name = field
                
                'Set the control chars
                lineData.control = "Down"
                lineData.index = 4
            Else
            
                
                'Extract the control
                If InStr(1, xmlLine, ":") Then
                    posInt = InStr(1, xmlLine, ":")
                    xmlLine = Right(xmlLine, Len(xmlLine) - posInt)
                End If
                
                If InStr(1, xmlLine, "/>") Then
                    'Extract the end control
                    posInt = InStr(1, xmlLine, "/>")
                    field = Left(xmlLine, posInt - 1)
                    lineData.name = field
                    
                    'Set the control chars
                    lineData.control = "Ignore"
                    lineData.index = 3
                    
                
                Else
                    'Extract the type
                    posInt = InStr(1, xmlLine, ">")
                    field = Trim(Left(xmlLine, posInt - 1))
                    lineData.name = field
                    
                    If InStr(1, xmlLine, "</") Then
                        'Extract the name
                        posInt = InStr(1, xmlLine, ">") + 1
                        posEnd = InStr(posInt, xmlLine, "</")
                        If posEnd >= posInt Then
                            field = Trim(Mid(xmlLine, posInt, posEnd - posInt))
                                            
                            lineData.value = field
                            lineData.control = "Same"
                            lineData.index = 0
                        End If
                    
                    Else
                        'Set the control info
                        lineData.control = "Up"
                        lineData.index = 2
                    
                    End If
                    
                End If '"/>"
            End If '"/"
        End If
        
    Else
        lineData.control = "Ignore"
    End If
    
    
    Set extract = lineData
    
    
    End Function
    In my case I had a need to filter control characters from the line prefixed with a ":", e.g. <xg:object id="ObjectName">, this part you could probably exclude.

    I then had an array tracking which object I was on as I moved along the xml tree.

    Feel free to customise or ignore to your preference :)

    Hope it helps,
    Vulcon.
    Last edited by vulcon; 11-17-2010 at 11:41 AM.
    Smile, And the whole world ...
    will want to know what your planning

Similar Threads

  1. Replies: 0
    Last Post: 04-20-2010, 06:29 PM
  2. work with xml in vb6
    By jason213123 in forum VB Classic
    Replies: 0
    Last Post: 04-03-2010, 12:02 PM
  3. Replies: 0
    Last Post: 04-25-2007, 06:54 PM
  4. XML parser problem (VB6)
    By chxxangie in forum VB Classic
    Replies: 3
    Last Post: 03-03-2007, 10:51 PM
  5. XML Security
    By HSIN NING in forum Web
    Replies: 0
    Last Post: 08-21-2000, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center