VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "dwHTMLelement"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' HTML element
' Desaware ActiveX Gallimaufry
' Copyright (c) 1997 by Desaware Inc.  All Rights Reserved

Option Explicit

Private intTag As String
Private intContents As String
Private separator As String

' Tag. Empty string for text
Public Function Tag() As String
   Tag = intTag
End Function

' Contents of tag element or text (if no tag)
Public Function Contents() As String
   Contents = intContents
End Function

' Loads the next tag or string element,
' Returns the balance of the string
Public Function LoadFromString(inputstring As String) As String
   Dim Bracket1Pos As Long
   Dim Bracket2pos As Long
   Dim holdstring As String
   Dim spacepos As Long
   Dim returnstring As String
   Bracket1Pos = InStr(inputstring, "<")
   Bracket2pos = InStr(inputstring, ">")
   If Bracket1Pos > 1 Then
      ' Everything up to the first bracket is content for
      ' this object
      holdstring = Left$(inputstring, Bracket1Pos - 1)
      returnstring = Mid$(inputstring, Bracket1Pos)
   Else
      If Bracket1Pos = 0 Then
         ' No tag present. The entire input string is content
         ' for this object.
         Debug.Assert True
         holdstring = inputstring
      Else
         ' It's the start of a tag
         If Bracket2pos = 0 Then  ' No right bracket!
            ' This should never happen on a valid page
            ' Just treat it as a string
            holdstring = inputstring
         Else
            ' Retrieve the entire tag for this object
            holdstring = LTrim$(Mid$(inputstring, 2, Bracket2pos - 2))
            If Bracket2pos < Len(inputstring) Then
               returnstring = Mid$(inputstring, Bracket2pos + 1)
            End If
         End If
      End If
   End If
   If holdstring <> "" Then ' Separate out the tag
      If Bracket1Pos <> 1 Then ' No tag - store the contents only
         intContents = holdstring
      Else
         ' It's a tag. Find the first delimiter character
         spacepos = StringSpan(holdstring, separator$)
         If spacepos <= 1 Then
            ' No delimiters indicates a tag with no parameters
            intTag = holdstring
         Else
            ' Place the tag in the intTag member,
            ' and the parameters in the intContents member
            intTag = Left$(holdstring, spacepos - 1)
            If spacepos < Len(holdstring) Then
               intContents = Mid$(holdstring, spacepos + 1)
            End If
         End If
      End If
   End If
   ' Trim on left
   spacepos = StringSpan2(returnstring, separator)
   If spacepos = 1 Then
      LoadFromString = returnstring
   Else
      If spacepos > 0 Then
         LoadFromString = Mid$(returnstring, spacepos)
      End If
   End If
End Function

Private Sub Class_Initialize()
   ' Initialize the separator string
   separator = " " & vbCrLf & vbTab
End Sub

