Results 1 to 4 of 4

Thread: HTMLStyle Object: How to get The Name, Value Pairs

  1. #1

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    HTMLStyle Object: How to get The Name, Value Pairs

    Hello Everyone! I hadn't been able to come around for a while but now I am back with an interesting question (At least for me )

    Anyway, Let's think you are checking each tag in a HTML Document Object and you get its HTMLStyle Object (oTag.Style) and now you want to know which of the styles are set (Example: color:blue; border: 1px solid black)

    I haven't found a way to do this without having to check the whole properties contained... Is there a way to iterate through all of them without having to type the whole list and checking every single one of them?

    I thought about getting the outerHTML and parsing the style but I would prefer to see if any of you can enlighten me with a clever way.

    Putting it short: I want to check which tag objects have in-line styles and which are their names and values. I am using an Internet Explorer application to do the HTML Parsing.

    Thank you very much for your time
    Last edited by Tec-Nico; Jan 9th, 2007 at 04:08 PM.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: HTMLStyle Object: How to know its contents

    How about posting url of a sample web page so we will all be referencing the same material.

  3. #3

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Re: HTMLStyle Object: How to know its contents

    You are right... I didn't have a specific page in mind thinking this could be used for any HTML document but let me add something here.

    We could also try this page:


    http://www.w3.org/TR/html401/struct/links.html

    Thank you for your help!
    Attached Files Attached Files
    Last edited by Tec-Nico; Jan 9th, 2007 at 10:36 AM. Reason: Added attachment
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

  4. #4

    Thread Starter
    Frenzied Member Tec-Nico's Avatar
    Join Date
    Jun 2002
    Location
    México
    Posts
    1,192

    Re: HTMLStyle Object: How to know its contents

    Here is what I had in mind doing if there was no better way.

    Maybe it will help people to see what I am trying to do...


    VB Code:
    1. Dim bHasStyle As Boolean
    2.  
    3.  Public Sub parseFile(sFileName As String)
    4.   Dim iE As Object
    5.   Dim HTMLDoc As Object
    6.   Dim oTag As Object
    7.  
    8.   Set iE = New InternetExplorer.Application
    9.   iE.Navigate(sFileName)
    10.  
    11.   Do while iE.readystate <> 4
    12.    DoEvents
    13.   Loop
    14.  
    15.   Set HTMLDoc = iE.document
    16.  
    17.   For Each oTag in HTMLDoc.All
    18.    processTag oTag
    19.   Next
    20.  
    21.   Set oTag = Nothing
    22.   Set HTMLDoc = Nothing
    23.   Set iE = Nothing
    24.  End Sub
    25.  
    26.  Private sub processTag(oTag As Object)
    27.   Dim iSSt As Integer
    28.   Dim sStyle As String
    29.   Dim Style As Object
    30.  
    31.   Set Style = New Scripting.Dictionary
    32.  
    33.   'Get the Index of the  style="
    34.   iSSt = InStr(1, oTag.outerHTML, " style=""") + 8
    35.   If iSSt > 8 Then
    36.    'Get the string isnde the style attribute:
    37.    sStyle = Trim(Mid(oTag.outerHTML, iSSt, InStr(iSSt, oTag.OuterHTML, """") - iSSt))
    38.    
    39.    'Begins Style gathering:
    40.    Dim i As Integer, iUBound As Integer, szStyles As String(), szNameValue As String()
    41.    
    42.    szStyles = Split(sStyle, ";") 'Get all the styles contained in the style string
    43.    iUBound = UBound(szStyles)
    44.    
    45.    'Loop the Array of Styles and split them in Name and Value separated by :
    46.    For i = 0 To iUBound
    47.     szNameValue = Split(szStyles(i), ":")
    48.     If UBound(szNameValue) > 0 Then 'Ensure it is not an empty array
    49.      If Style.Exists(szNameValue(0)) Then
    50.       Style(szNameValue(0)) = szNameValue(1)
    51.      Else
    52.       Style.Add szNameValue(0), szNameValue(1)
    53.      End If
    54.     End If
    55.    Next
    56.    
    57.    bHasStyle = iUBound >= 0
    58.    'Ends Style gathering
    59.    
    60.    'Process the style data...
    61.   End If
    62.  
    63.   Set Style = Nothing
    64.  End Sub

    Thank you, guys.
    We miss you, friend... Rest in Peace, we will take care of the rest of it.

    [vbcode]
    On Error Me.Fault = False
    [/vbcode]
    - Silence is the human way to share ignorance
    Tec-Nico

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