AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Sintaxis WLanguage / Instrucciones estructuradas
  • Syntax 1: Traversing elements of the XML file on one level
  • Syntax 2: Route on one level with copy
  • Syntax 3: Depth travel
  • Loop through an XMLDocument variable
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
The FOR EACH statement loops through a variable of type xmlReader in various ways:
  • Loop through a level.
  • Loop through a level with copy.
  • In-depth loop.
Note: The FOR EACH, FOR ALL statements are accepted. The FOR EACH statement will be used in this documentation but it can be replaced with FOR ALL.
Ejemplo
<?xml version="1.0"?>
<aa>
<bb>
Text1

<cc>
</cc>
</bb>
<bb>
<cc>
</cc>
</bb>
</aa>
// Parcours sur un niveau
// Lecteur est la variable correspondant au fichier XML
FOR EACH Lecteur
	// Lecture des balises début aa et fin aa
	FOR EACH Lecteur
		// Lecture des balises début bb, fin bb, début bb, fin bb
		FOR EACH Lecteur
		// Lecture de Text1 et des balises début cc, fin cc
		// début cc, fin cc
		END
	END
END
// Lecteur est la variable correspondant au fichier XML
FOR EACH Lecteur IN-DEPTH
	// Lecture des balises début aa, début bb, text1, 
	// début cc, fin cc, fin bb, début bb,
	// début cc, fin cc, fin bb, fin aa
END
Sintaxis

Iterating over the elements of the XML file on a level Ocultar los detalles

FOR EACH <XML Reader>
      FOR EACH <XML Reader>
    ...
      END
END
<FOR EACH>:
Marks the beginning of the statement block.
Used to iterate over the children of the current level.
<XML Reader>:
xmlReader variable corresponding to the XML file to loop through.
Inside the loop, the xmlReader variable points to the current XML element.
Note: It is possible to nest paths on the XML player.

Loop through a level with copy Ocultar los detalles

FOR EACH <Element> OF <XML Reader>
       FOR EACH <Element A> OF <Element>
        ...
       END
END
<FOR EACH>:
Marks the beginning of the statement block.
Used to iterate over the children of the current level.
<Element>:
Inside the loop, <Element> points to the current XML element. It can be used to perform a new FOR EACH loop to iterate over its children.
<XML Reader>:
xmlReader variable corresponding to the XML file to loop through.

In-depth loop Ocultar los detalles

FOR EACH <XML Reader> IN-DEPTH
      ...
END

FOR EACH <Element> OF <XML Reader> IN-DEPTH
      ...
END
<FOR EACH>:
Marks the beginning of the statement block.
Goes deep into the XML tree: traverses son, then grandson, then grandson's son to a leaf, continuing.
<Element>:
Inside the loop, <Element> points to the current XML element. Used to perform a reading in depth from an element.
<XML Reader>:
xmlReader variable corresponding to the XML file to loop through.
Observaciones

Syntax 1: Traversing elements of the XML file on one level

This syntax is used to iterate over the children of the current level. Inside the loop, the xmlReader variable points to the current XML element.
You can nest loops on the xmlReader variable to iterate over the children of the element on the current level.

Syntax 2: Route on one level with copy

This syntax is used to iterate over the children of the current level. Inside the loop, <Element> points to the current XML element and it is possible to use it to perform another loop on its own children.
Note: It is possible to perform only one browse on the variable <Elément>.

Syntax 3: Depth travel

This syntax allows you to traverse the XML tree in depth, i.e. son, then grandson, ... until you reach a leaf. When the leaf is reached, the loop goes to the next child.

Loop through an XMLDocument variable

If the XML file is handled via a variable of type XMLDocument, you can loop through the data file directly.
For example:
// Use of FOR EACH <xmlNode> OF <xmlNode or xmlDocument> 
// ON <Node name> WHERE <CONDITION>

// Search for all the rows in the invoice with a VAT of 20
sXML is string=[
<?xml version="1.0" encoding="UTF-8"?>
<INVOICE>
	<HEADER>
		<CLIENTID>123465</CLIENTID>
		<NAME>M. Henry DOUGLAS</NAME>
	</HEADER>
	<ROWS>
		<LIGNE TYPE="PRODUIT" CODE="CD1" QTE="2" TYPTVA="5.5">51</LIGNE>
		<ROW TYPE="PRODUCT" CODE="CD2" QTY="1" VATTYP="20">52</ROW>
		<ROW TYPE="PRODUCT" CODE="CD3" QTY="3" VATTYP="5.5">53</ROW>
		<ROW TYPE="PRODUCT" CODE="CD4" QTY="1" VATTYP="20">54</ROW>
		<ROW TYPE="PRODUCT" CODE="CD5" QTY="1" VATTYP="20">55</ROW>
		<ROW TYPE="PRODUCT" CODE="CD6" QTY="1" VATTYP="5.5">56</ROW>
	</ROWS>
	<TOTALS>
		<VAT TYPE="5.5">55</VAT>
		<VAT TYPE="20">200</VAT>
		<TOTALBT>1000</TOTALBT>
		<SHIPCOST>10</SHIPCOST>
	</TOTALS>
</INVOICE>
]

resultXML is xmlDocument = XMLOpen(sXML, fromString)
IF ErrorOccurred THEN
	Error("Unable to open the XML file", ErrorInfo())
	RETURN
END
// Loop through "INVOICE.ROWS" only 
// on the subnodes with the name "ROW" 
// and where the "VATTYP" attribute is set to "20" 
FOR EACH RowNode OF resultXml.INVOICE.ROWS 
			ON ROW where RowNode:VATTYP.Value = "20"
	Trace("Item " + RowNode:CODE.Value + " x " + ...
		RowNode:QTY.Value+" = " + RowNode..Text)
END
Versión mínima requerida
  • Versión 23
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 14/05/2025

Señalar un error o enviar una sugerencia | Ayuda local