ComposantsComponents › Fichier › SortieFile › Output
Écrit les lignes de plusieurs flux dans un seul document XML. Chaque flux a son propre arbre, dessiné dans l'éditeur du composant à partir d'un élément racine commun : ses lignes vont dans une branche à part, ou, avec un élément de groupe, dans les éléments créés par un flux précédent (les lignes d'une commande dans sa commande). Le document est construit en mémoire, puis écrit à la fin. Writes the rows of several flows into one XML document. Each flow has its own tree, drawn in the editor of the component from a common root element: its rows go into a separate branch, or, with a group element, into the elements created by a previous flow (the lines of an order inside their order). The document is built in memory, then written at the end.
EntréeInput
Merge un lien par flux, au moins un, sans limite ; l'ordre des liens compteone link per flow, at least one, no limit; the order of the links matters
SortieOutput
Aucune : pas de flux de sortie. Le résultat est le fichier écrit. None: no output flow. The result is the written file.
Déclencheurs en sortieOutput triggers
On Component Ok On Component Error Run if
Le flux parent (orders) est relié en premier : ses éléments doivent exister quand arrivent les lignes du flux enfant.
The parent flow (orders) is connected first: its elements must exist when the rows of the child flow arrive.
id, lié ici à order_id), clic droit › Définir comme élément de groupe, et mettez l'élément de boucle dessous.
To put the rows of a child flow into the elements of the parent: in its tree, repeat the repeated element of the parent, with the same path and the key at the same place (the id attribute, linked here to order_id), right-click › Set As Group Element, and put the loop element under it.
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de schéma propre : il prend celui de chaque lien entrant. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no schema of its own: it takes the one of each incoming link.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Nom de fichierFile NameFILENAME | chemin par défaut + /out.xmldefault path + /out.xml |
ToujoursAlways |
Le fichier écrit, en expression Java : context.folder + "/orders.xml". Il est remplacé s'il existe.
The written file, as a Java expression: context.folder + "/orders.xml". It is replaced if it exists.
|
| Configurer l'arbre XMLConfigure XML TreeMAP | — | ToujoursAlways |
Ouvre l'éditeur des arbres, un par flux. Les arbres sont enregistrés dans trois tables cachées du composant, ROOT, GROUP et LOOP (éléments au-dessus du groupe, groupe, boucle).
Opens the editor of the trees, one per flow. The trees are saved in three hidden tables of the component, ROOT, GROUP and LOOP (elements above the group, group, loop).
|
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Créer le répertoire seulement s'il n'existe pasCreate directory only if it does not existCREATE | OuiYes | ToujoursAlways | Crée le dossier du fichier, avec ses parents, au démarrage du composant. Creates the folder of the file, with its parents, when the component starts. |
| Créer un élément vide si nécessaireCreate empty element if neededCREATE_EMPTY_ELEMENT | OuiYes | ToujoursAlways |
Coché, un élément dont la colonne vaut null est écrit vide (<name/>). Décoché, les éléments vides sont retirés du document (voir les exemples).
Checked, an element whose column is null is written empty (<name/>). Unchecked, the empty elements are removed from the document (see the examples).
|
| Séparateur avancé (pour les nombres)Advanced separator (for numbers)ADVANCED_SEPARATOR | NonNo | ToujoursAlways | Écrit les nombres avec les séparateurs ci-dessous (d'après le modèle, non essayé). Writes the numbers with the separators below (according to the template, not tried). |
| Séparateur de milliersThousands separatorTHOUSANDS_SEPARATOR | "," |
Séparateur avancé cochéAdvanced separator checked | Un caractère, entre guillemets. One character, in quotes. |
| Séparateur décimalDecimal separatorDECIMAL_SEPARATOR | "." |
Séparateur avancé cochéAdvanced separator checked | Un caractère, entre guillemets. One character, in quotes. |
| EncodageEncodingENCODING | "ISO-8859-15" |
ToujoursAlways |
L'encodage du fichier, repris dans la déclaration XML : <?xml version="1.0" encoding="ISO-8859-15"?>.
The encoding of the file, repeated in the XML declaration: <?xml version="1.0" encoding="ISO-8859-15"?>.
|
| Ne pas générer de fichier videDon't generate empty fileDELETE_EMPTYFILE | NonNo | ToujoursAlways | Sans aucune ligne reçue, le fichier est supprimé après l'écriture (d'après le modèle, non essayé). With no row received, the file is deleted after the writing (according to the template, not tried). |
| Supprimer les caractères d'espaceTrim the whitespace charactersTRIM_TEXT | OuiYes | ToujoursAlways |
Retire les espaces en trop du texte des éléments : " Ada " devient Ada (voir l'exemple).
Removes the excess spaces from the text of the elements: " Ada " becomes Ada (see the example).
|
| Échapper le texteEscape TextESCAPE_TEXT | OuiYes | ToujoursAlways |
Écrit &, < et > du texte en &, <, >. Décoché, ils sont écrits tels quels et le fichier n'est plus un XML valide (voir l'exemple).
Writes &, < and > of the text as &, <, >. Unchecked, they are written as is and the file is no longer valid XML (see the example).
|
NB_LINE (Integer, disponible après l'exécution du composant) : nombre de lignes reçues, tous flux confondus. NB_LINE (Integer, available after the component has run): number of rows received, all flows together.
((Integer) globalMap.get("tFileOutputMSXML_1_NB_LINE"))
Les flux viennent de tFixedFlowInput en mode tableau. Le fichier est écrit dans le dossier de la variable de contexte folder ; un tJava relié par On Subjob Ok au premier tFixedFlowInput le lit en ISO-8859-15 et l'affiche ligne par ligne, puis affiche NB_LINE. Dans les arbres, ← donne la colonne liée. Les sorties sont celles de la console, copiées depuis une exécution du job.
The flows come from tFixedFlowInput components in table mode. The file is written in the folder of the folder context variable; a tJava connected with On Subjob Ok to the first tFixedFlowInput reads it in ISO-8859-15 and prints it line by line, then prints NB_LINE. In the trees, ← gives the linked column. The outputs are the console ones, copied from a run of the job.
orders (id, customer) : 1 Ada, 2 Grace, 3 Alan. lines (order_id, product, qty) : 2 Ink 1, 1 Pen 3, 9 Glue 2, 1 Paper 10. Arbre de orders :
orders (id, customer): 1 Ada, 2 Grace, 3 Alan. lines (order_id, product, qty): 2 Ink 1, 1 Pen 3, 9 Glue 2, 1 Paper 10. Tree of orders:
orders
└─ order (boucleloop) @id ← id
└─ customer ← customer
Arbre de lines :Tree of lines:
orders
└─ order (groupegroup) @id ← order_id
└─ line (boucleloop) ← product, @qty ← qty
<?xml version="1.0" encoding="ISO-8859-15"?>
<orders>
<order id="1">
<customer>Ada</customer>
<line qty="3">Pen</line>
<line qty="10">Paper</line>
</order>
<order id="2">
<customer>Grace</customer>
<line qty="1">Ink</line>
</order>
<order id="3">
<customer>Alan</customer>
</order>
<order id="9">
<line qty="2">Glue</line>
</order>
</orders>
NB_LINE: 7
Chaque ligne entre dans la commande dont l'attribut id vaut son order_id, après le client. La ligne Glue ne trouve pas de commande 9 : un élément <order id="9"> est créé pour elle, sans client.
Each line goes into the order whose id attribute equals its order_id, after the customer. The Glue line finds no order 9: an <order id="9"> element is created for it, without a customer.
customers (id, name) : 1 Ada, 2 null. products (code, label) : P1 Pen, P2 Ink. Les deux arbres partagent la racine data :
customers (id, name): 1 Ada, 2 null. products (code, label): P1 Pen, P2 Ink. Both trees share the data root:
data
└─ customers
└─ customer (boucleloop) @id ← id
└─ name ← name
data
└─ products
└─ product (boucleloop) @code ← code
└─ label ← label
<?xml version="1.0" encoding="ISO-8859-15"?>
<data>
<customers>
<customer id="1">
<name>Ada</name>
</customer>
<customer id="2">
<name/>
</customer>
</customers>
<products>
<product code="P1">
<label>Pen</label>
</product>
<product code="P2">
<label>Ink</label>
</product>
</products>
</data>
NB_LINE: 4
products partage data avec customers : sa branche est ajoutée sous data, après celle des clients.
products shares data with customers: its branch is added under data, after the customers one.
Le même job, Créer un élément vide si nécessaire décoché : The same job, Create empty element if needed unchecked:
<?xml version="1.0" encoding="ISO-8859-15"?>
<data>
<customers>
<customer id="1">
<name>Ada</name>
</customer>
<customer id="2"/>
</customers>
<products>
<product code="P1">
<label>Pen</label>
</product>
<product code="P2">
<label>Ink</label>
</product>
</products>
</data>
NB_LINE: 4
L'élément <name/> du client 2 a disparu ; le client reste, il a un attribut.
The <name/> element of customer 2 is gone; the customer stays, it has an attribute.
Deux composants, chacun avec un flux d'une colonne label : Pen & <Ink> et " Ada " ; arbre items › item (boucle) ← label. Le premier garde les réglages par défaut, le second décoche Échapper le texte et Supprimer les caractères d'espace. Le tJava affiche chaque ligne entre crochets :
Two components, each one with a flow of one label column: Pen & <Ink> and " Ada "; tree items › item (loop) ← label. The first one keeps the default settings, the second one unchecks Escape Text and Trim the whitespace characters. The tJava prints each line between brackets:
text_default.xml [<?xml version="1.0" encoding="ISO-8859-15"?>] [] [<items>] [ <item>Pen & <Ink></item>] [ <item>Ada</item>] [</items>]
text_raw.xml [<?xml version="1.0" encoding="ISO-8859-15"?>] [] [<items>] [ <item>Pen & <Ink></item>] [ <item> Ada </item>] [</items>]
Le nom du job est remplacé par MyJob, les chemins sont abrégés.
The job name is replaced with MyJob, paths are shortened.
Le composant a besoin de mvn:org.talend.libraries/xmlUtil/6.0.0, qui n'est sur aucun dépôt Maven public. Le Studio la livre dans son plugin org.talend.libraries.xml (fichier lib/xmlUtil.jar). Exécuté hors du Studio sans elle, le job du deuxième exemple ne compile pas :
The component needs mvn:org.talend.libraries/xmlUtil/6.0.0, which is on no public Maven repository. The Studio ships it in its org.talend.libraries.xml plugin (file lib/xmlUtil.jar). Run outside the Studio without it, the job of the second example does not compile:
Library not found: mvn:org.talend.libraries/xmlUtil/6.0.0 MyJob.java:1251: error: package org.talend.util.xml does not exist isXML10Char_tFileOutputMSXML_1 = org.talend.util.xml.XMLText.isValid( ^ … 4 errors
Copiez xmlUtil.jar du Studio dans le dépôt Maven local, sous org/talend/libraries/xmlUtil/6.0.0/xmlUtil-6.0.0.jar. Les deux autres bibliothèques, dom4j 2.1.3 et jaxen 1.2.0, viennent de Maven Central.
Copy xmlUtil.jar from the Studio into the local Maven repository, under org/talend/libraries/xmlUtil/6.0.0/xmlUtil-6.0.0.jar. The two other libraries, dom4j 2.1.3 and jaxen 1.2.0, come from Maven Central.
Le premier exemple, mais lines relié en premier (Merge order:1) et orders en second, les arbres inchangés :
The first example, but lines connected first (Merge order:1) and orders second, the trees unchanged:
<?xml version="1.0" encoding="ISO-8859-15"?>
<orders>
<order id="2">
<line qty="1">Ink</line>
</order>
<order id="1">
<line qty="3">Pen</line>
<line qty="10">Paper</line>
</order>
<order id="9">
<line qty="2">Glue</line>
</order>
<order id="1">
<customer>Ada</customer>
</order>
<order id="2">
<customer>Grace</customer>
</order>
<order id="3">
<customer>Alan</customer>
</order>
</orders>
NB_LINE: 7
Les lignes arrivent les premières et créent leurs propres éléments order ; les commandes, qui n'ont pas de groupe, en ajoutent d'autres. Aucune erreur ne le signale : reliez toujours le flux parent en premier.
The lines arrive first and create their own order elements; the orders, which have no group, add other ones. No error reports it: always connect the parent flow first.
Le document entier est construit en mémoire (dom4j) et écrit à la fin. Pour un gros volume, prévoyez la mémoire de la JVM (-Xmx).
The whole document is built in memory (dom4j) and written at the end. For a large volume, plan the JVM memory (-Xmx).
Une ligne enfant sans parent crée un élément de groupe à elle, comme <order id="9">. Pour écarter ces lignes, faites la jointure avant le composant (tJoin, avec ses rejets).
A child row without a parent creates a group element of its own, like <order id="9">. To discard these rows, do the join before the component (tJoin, with its rejects).
Le composant marche aussi avec un seul lien. Pour un seul flux, tFileOutputXML suffit. The component also works with a single link. For a single flow, tFileOutputXML is enough.
Laissez Échapper le texte coché, sauf si les colonnes contiennent déjà du XML échappé : un & seul rend le fichier illisible pour un lecteur XML.
Leave Escape Text checked, unless the columns already hold escaped XML: a lone & makes the file unreadable for an XML reader.
tFileOutputXML · un seul flux dans un fichier XMLa single flow into an XML filetFileOutputMSDelimited · plusieurs flux liés dans un fichier délimitéseveral linked flows into a delimited filetFileOutputMSPositional · plusieurs flux liés en largeur fixeseveral linked flows in fixed widthtFileOutputJSON · écrire un flux en JSONwrite a flow as JSONtJoin · écarter les lignes sans parent avant l'écriturediscard the rows without a parent before writingtChangeFileEncoding · changer l'encodage du fichier après coupchange the encoding of the file afterwards