Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
HTML mailmerge templates
Message
De
29/11/2020 06:16:48
 
 
À
29/11/2020 03:27:54
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Divers
Thread ID:
01677316
Message ID:
01677323
Vues:
78
>Hi Antonio,
>
>Excellent. Thanks very much. This will get me closer to where I want to go.
>
>One last question. What is the best way to iterate through the fields to process them. Is there a collection I can iterate through to get all the fields ?
>
>Walter,
>

Yes, Walter, you can traverse the list of <span> elements in the document, and process those that belong to the "field" class (of course, you can name the class whatever you want).

Two new methods: get a collection of field ids from the document, and fetch the final result.
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
----------------------------------
António Tavares Lopes
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform