|
|
|
|
- Sintaxis 1: Iterar sobre los elementos del archivo XML en un nivel
- Sintaxis 2: Recorrer un nivel con copy
- Sintaxis 3: Bucle de profundidad
- Bucle a través de una xmlDocument Variable
Declaración FOR EACH/FOR ALL (bucle a través de una variable de tipo xmlReader)
La declaración FOR EACH recorre un Variable de tipo xmlReader de varias maneras: - Recorrer un nivel en bucle.
- Recorrer un nivel con copy.
- Bucle de profundidad.
Observación: Se aceptan las sentencias FOR ALL, FOR EACH. La instrucción FOR EACH se usará en esta documentación, pero se puede reemplazar con FOR ALL . < ?xml version="1.0"?>
<aa>
<bb>
Text1
<cc>
</cc>
</bb>
<bb>
<cc>
</cc>
</bb>
</aa> // Loop through a level // Reader is the variable corresponding to the XML file FOR EACH Reader // Read the start aa and end aa tags FOR EACH Reader // Read the start bb, end bb, start bb, end bb tags FOR EACH Reader // Read Text1 and the start cc, end cc // start cc, end cc tags END END END
// Reader is the variable corresponding to the XML file FOR EACH Reader IN-DEPTH // Read the start aa, start bb, text1, // start cc, end cc, end bb, start bb, // start cc, end cc, end bb, end aa tags END
Sintaxis
Iterar sobre los elementos del archivo XML en un nivel Ocultar los detalles
FOR EACH <XML Reader> FOR EACH <XML Reader> ... END END
<FOR EACH>: Marca el inicio del bloque de instrucciones. Se utiliza para iterar sobre los hijos del nivel actual. <XML Reader>: xmlReader Variable correspondiente al archivo XML a recorrer. Dentro del bucle, la xmlReader Variable apunta al elemento XML actual. Observación: Puede anidar bucles en el lector XML.
Recorrer un nivel con copy Ocultar los detalles
FOR EACH <Element> OF <XML Reader> FOR EACH <Element A> OF <Element> ... END END
<FOR EACH>: Marca el inicio del bloque de instrucciones. Se utiliza para iterar sobre los hijos del nivel actual. <Element>: Dentro del bucle, apunta al elemento XML actual. Se puede utilizar para realizar un nuevo bucle FOR EACH para iterar sobre sus hijos. <XML Reader>: xmlReader Variable correspondiente al archivo XML a recorrer.
Bucle de profundidad Ocultar los detalles
FOR EACH <XML Reader> IN-DEPTH ... END
FOR EACH <Element> OF <XML Reader> IN-DEPTH ... END
<FOR EACH>: Marca el inicio del bloque de instrucciones. Se utiliza para recorrer el árbol XML en profundidad: iterar sobre el hijo, el nieto y luego el hijo del nieto hasta llegar a una hoja. <Element>: Dentro del bucle, apunta al elemento XML actual. Se utiliza para realizar una lectura en profundidad de un elemento. <XML Reader>: xmlReader Variable correspondiente al archivo XML a recorrer. Observaciones Sintaxis 1: Iterar sobre los elementos del archivo XML en un nivel Esta sintaxis se utiliza para iterar sobre los hijos del nivel actual. Dentro del bucle, la xmlReader Variable apunta al elemento XML actual. Puede anidar bucles en la xmlReader Variable para iterar sobre los hijos del elemento en el nivel actual. Sintaxis 2: Recorrer un nivel con copy Esta sintaxis se utiliza para iterar sobre los hijos del nivel actual. Dentro del bucle, apunta al elemento XML actual y es posible utilizarlo para realizar otro bucle sobre sus propios hijos. Observación: Se puede realizar una única iteración en la Variable. Sintaxis 3: Bucle de profundidad Esta sintaxis se utiliza para recorrer el árbol XML en profundidad, es decir, iterar sobre los hijos, nietos, ... hasta que se alcanza una hoja. Cuando se alcanza la hoja, el bucle pasa al siguiente hijo.. Bucle a través de una xmlDocument Variable Si el archivo XML se maneja a través de una Variable de tipo XMLDocument, puede recorrer el archivo directamente. Por ejemplo: // 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> <ROW TYPE="PRODUCT" CODE="CD1" QTY="2" VATTYP="5.5">51</ROW> <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.INVOCE.ROWS ON ROW where RowNode:VATTYP.Value = "20" Trace("Item " + RowNode:CODE.Value + " x " + ... RowNode:QTY.Value+" = " + RowNode..Text) END
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|