LOCAL HTMLSource AS String TEXT TO m.HTMLSource NOSHOW FLAGS 1 <html> <head> <title>A document</title> <style>.field {color: red}</style> </head> <body> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <span id="field001" class="field">Field #1</span> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <span id="field002" class="field">Field #2</span> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est <span class="not_a_field">laborum</span>.</p> </body> </html> ENDTEXT STRTOFILE(m.HTMLSource, "wm.html") LOCAL Browser AS BrowserForm LOCAL FieldsInDoc AS Collection LOCAL FieldId AS String m.Browser = CREATEOBJECT("BrowserForm") m.Browser.Show() WAIT WINDOW "Load the document..." m.Browser.LoadDocument(FULLPATH("wm.html")) WAIT WINDOW "Set random field values..." m.FieldsInDoc = m.Browser.GetFieldsInDocument() FOR EACH m.FieldId IN m.FieldsInDoc m.Browser.ProcessField(m.FieldId, SYS(3)) ENDFOR WAIT WINDOW "Done, show the result!" MESSAGEBOX(m.Browser.GetProcessedText()) DEFINE CLASS BrowserForm AS Form ADD OBJECT HtmlViewer AS OleControl WITH Width = This.Width, Height = This.Height, OleClass = "Shell.Explorer" PROCEDURE Init This.HtmlViewer.Navigate2("about:blank") ENDPROC PROCEDURE LoadDocument (Document AS String) This.HtmlViewer.Navigate2(m.Document) ENDPROC PROCEDURE ProcessField (FieldId AS String, FieldValue AS String) This.HtmlViewer.Document.getElementById(m.FieldId).innerText = m.FieldValue ENDPROC PROCEDURE GetFieldsInDocument () AS Collection LOCAL AllFields AS Collection LOCAL Spans AS Object LOCAL Span AS Object m.AllFields = CREATEOBJECT("Collection") m.Spans = This.HtmlViewer.Document.getElementsByTagName("span") FOR EACH m.Span IN m.Spans IF m.Span.className == "field" m.AllFields.Add(m.Span.Id) ENDIF ENDFOR RETURN m.AllFields ENDPROC PROCEDURE GetProcessedText () RETURN This.HtmlViewer.Document.documentElement.innerHTML ENDPROC ENDDEFINE