|
|
|
|
|
- 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
FOR EACH/FOR ALL statement (loop through a variable of type XMLReader) In french: POUR TOUT / POUR TOUS
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. <?xml version="1.0"?>
<aa>
<bb>
Text1
<cc>
</cc>
</bb>
<bb>
<cc>
</cc>
</bb>
</aa>
FOR EACH Lecteur
FOR EACH Lecteur
FOR EACH Lecteur
END
END
END
FOR EACH Reader IN-DEPTH
END
Syntax
Iterating over the elements of the XML file on a level Hide the details
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 Hide the details
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 Hide the details
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. Remarks 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>. 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:
sXML is string=[
<?xml version="1.0" encoding="UTF-8"?>
<FACTURE>
<ENTETE>
<IDCLIENT>123465</IDCLIENT>
<NOM>M. Henri DUPONT</NOM>
</ENTETE>
<LIGNES>
<LIGNE TYPE="PRODUIT" CODE="CD1" QTE="2" TYPTVA="5.5">51</LIGNE>
<LIGNE TYPE="PRODUIT" CODE="CD2" QTE="1" TYPTVA="20">52</LIGNE>
<LIGNE TYPE="PRODUIT" CODE="CD3" QTE="3" TYPTVA="5.5">53</LIGNE>
<LIGNE TYPE="PRODUIT" CODE="CD4" QTE="1" TYPTVA="20">54</LIGNE>
<LIGNE TYPE="PRODUIT" CODE="CD5" QTE="1" TYPTVA="20">55</LIGNE>
<LIGNE TYPE="PRODUIT" CODE="CD6" QTE="1" TYPTVA="5.5">56</LIGNE>
</LIGNES>
<TOTAUX>
<TVA TYPE="5.5">55</TVA>
<TVA TYPE="20">200</TVA>
<TOTALHT>1000</TOTALHT>
<FDP>10</FDP>
</TOTAUX>
</FACTURE>
]
resultXml is xmlDocument = XMLOpen(sXML, fromString)
IF ErrorOccurred THEN
Error("Echec de l'ouverture du XML", ErrorInfo())
RETURN
END
FOR EACH NoeudLigne OF resultXml.FACTURE.LIGNES
ON LIGNE WITH NoeudLigne:TYPTVA.Valeur = "20"
Trace("Article code " + NoeudLigne:CODE.Valeur + " x " + ...
NoeudLigne:QTE.Valeur+" = " + NoeudLigne..Text)
END
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|