ComposantsComponents

ComposantsComponents › Fichier › SortieFile › Output

tAdvancedFileOutputXML

tAdvancedFileOutputXML

Fichier › SortieFile › Output XML

Écrit les lignes d'un flux dans un fichier XML dont la forme est dessinée dans un arbre : racine, éléments et attributs liés aux colonnes, élément de boucle répété pour chaque ligne, élément de groupe facultatif qui réunit les lignes de même valeur. Toutes les lignes vont dans un seul document, indenté ou compact ; le composant sait aussi découper le fichier, écrire à la suite d'un fichier existant, déclarer une DTD ou une feuille XSL et produire un schéma XSD. Pour une structure fixe d'une balise par ligne, le tFileOutputXML suffit ; pour un document par ligne dans une colonne, voyez le tWriteXMLField. Writes the rows of a flow to an XML file whose shape is drawn in a tree: root, elements and attributes linked to the columns, loop element repeated for each row, optional group element that gathers the rows with the same value. All the rows go into a single document, indented or compact; the component can also split the file, append to an existing file, declare a DTD or an XSL stylesheet and produce an XSD schema. For a fixed structure of one tag per row, the tFileOutputXML is enough; for one document per row in a column, see the tWriteXMLField.

EntréeInput

Main un flux, obligatoire : sans lui, le composant ne génère aucun codeone flow, required: without it, the component generates no code

SortieOutput

Main un flux, facultatif : les lignes repartent telles quellesone flow, optional: the rows go on unchanged

Déclencheurs en sortieOutput triggers

On Component Ok On Component Error Run if

UtilisationUsage

Au bout d'un fluxAt the end of a flow

row1 (Main) tFileInputDelimited_1 tAdvancedFileOutputXML_1

Le cas courant : chaque ligne lue ajoute un élément de boucle au document, écrit dans le fichier à la fin du flux. The common case: each row read adds a loop element to the document, written to the file at the end of the flow.

Lignes triées puis regroupéesRows sorted then grouped

row1 (Main) row2 (Main) tFileInputDelimited_1 tSortRow_1 tAdvancedFileOutputXML_1

Avec un élément de groupe, triez d'abord le flux sur les colonnes du groupe : un groupe commence à chaque changement de valeur. With a group element, sort the flow on the group columns first: a group starts at each change of value.

  1. Déposez le tAdvancedFileOutputXML depuis la famille Fichier › Sortie (ou XML) de la palette et reliez-lui le flux à écrire : son schéma se remplit à partir du lien. Drop the tAdvancedFileOutputXML from the File › Output (or XML) family of the palette and connect the flow to write to it: its schema is filled from the link.
  2. Indiquez le Nom de fichier. Set the File Name.
  3. Ouvrez Configurer l'arbre XML (bouton …, ou double clic) : nommez la racine, ajoutez les éléments et les attributs, glissez les colonnes dessus, puis désignez l'élément de boucle et, au besoin, l'élément de groupe. L'éditeur est celui du tWriteXMLField ; l'arbre peut aussi venir d'une métadonnée Fichier XML de sortie du Référentiel. Open Configure XML Tree (… button, or double-click): name the root, add the elements and the attributes, drag the columns on them, then set the loop element and, if needed, the group element. The editor is the one of the tWriteXMLField; the tree can also come from an output XML file metadata of the Repository.
  4. Dans les Paramètres avancés, choisissez l'Encodage ("ISO-8859-15" par défaut) et le Mode de génération. In the Advanced settings, choose the Encoding ("ISO-8859-15" by default) and the Generation mode.

Modes de générationGeneration modes

Dom4J (défautdefault)

Libellé « Lent et consommateur de mémoire ». Tout le document est construit en mémoire avec la bibliothèque dom4j, puis écrit à la fin du flux, avec des fins de ligne \n. Seul ce mode permet d'écrire à la suite d'un fichier, de supprimer les espaces des données et d'insérer une colonne Document comme des nœuds. Label “Slow and memory-consuming”. The whole document is built in memory with the dom4j library, then written at the end of the flow, with \n line ends. Only this mode can append to a file, trim the data and insert a Document column as nodes.

RapideFast (Null)

Libellé « Rapide avec peu de consommation de mémoire ». Le texte est écrit au fil des lignes, sans garder le document : pour les gros fichiers. Sur les exemples, mêmes fichiers qu'en Dom4j, sauf : sous Windows, fins de ligne mêlant \n et \r\n et pas de saut de ligne final ; guillemets du texte écrits &quot; ; éléments vides écrits <note></note>. Label “Fast with low memory consumption”. The text is written as the rows come, without keeping the document: for large files. On the examples, same files as in Dom4j, except: on Windows, line ends mixing \n and \r\n and no final line break; quotes of the text written &quot;; empty elements written <note></note>.

Paramètres simplesBasic settings

Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Noms de fichier et réglages texte sont des expressions Java : "customers.dtd", context.folder + "/out.xml". Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. File names and text settings are Java expressions: "customers.dtd", context.folder + "/out.xml".

ParamètreSetting DéfautDefault VisibleShown Description
Type de propriétéProperty TypePROPERTY Built-in ToujoursAlways Built-in : réglages saisis dans le composant. Référentiel : le fichier de sortie, l'arbre et l'encodage viennent d'une métadonnée Fichier XML de sortie. Built-In: settings typed in the component. Repository: the output file, the tree and the encoding come from an output XML file metadata.
Utiliser le flux de sortieUse Output StreamUSESTREAM NonNo ToujoursAlways Écrit dans un java.io.OutputStream au lieu d'un fichier. Le flux n'est pas fermé. Découpage, écriture à la suite, XSD, création du dossier et fichier vide ne s'appliquent plus (voir l'exemple). Writes to a java.io.OutputStream instead of a file. The stream is not closed. Split, append, XSD, folder creation and empty file no longer apply (see the example).
Flux de sortieOutput StreamSTREAMNAME outputStream Flux cochéStream checked Expression Java qui donne le flux : System.out, ou (java.io.OutputStream) globalMap.get("out") pour un flux ouvert plus tôt dans le job. Le défaut, sans guillemets, désigne une variable outputStream que le job devrait fournir : remplacez-le par l'expression du flux. Java expression that gives the stream: System.out, or (java.io.OutputStream) globalMap.get("out") for a stream opened earlier in the job. The default, without quotes, designates an outputStream variable the job would have to provide: replace it with the expression of the stream.
Nom de fichierFile NameFILENAME chemin par défaut + /out.xmldefault path + /out.xml Flux décochéStream unchecked Le fichier écrit, remplacé à chaque exécution (sauf écriture à la suite). Il sert aussi à nommer les fichiers découpés et le fichier XSD. The written file, replaced at each run (except when appending). It is also used to name the split files and the XSD file.
Configurer l'arbre XMLConfigure XML TreeMAP — ToujoursAlways Bouton qui ouvre l'éditeur de l'arbre (voir l'arbre XML). L'arbre est rangé dans les tables masquées ROOT, GROUP et LOOP. Sans élément de boucle, le composant ne génère aucun code. Button that opens the tree editor (see the XML tree). The tree is stored in the hidden tables ROOT, GROUP and LOOP. Without a loop element, the component generates no code.
SchémaSchemaSCHEMA — ToujoursAlways Les colonnes reçues, que l'arbre peut lier. Une colonne Date a besoin d'un modèle de date (voir les erreurs) ; une colonne BigDecimal avec une précision est arrondie à cette précision (voir les exemples). The received columns, which the tree can link. A Date column needs a date pattern (see the errors); a BigDecimal column with a precision is rounded to this precision (see the examples).
Écrire les données à la fin du fichier XML sourceAppend the source xml fileMERGE NonNo Mode Dom4J, flux décochéDom4J mode, stream unchecked Relit le fichier existant et y ajoute les lignes : une ligne dont le groupe existe déjà rejoint ce groupe, les autres créent le leur (voir l'exemple). L'arbre doit avoir un élément de groupe : sans lui, le job s'arrête (voir les erreurs). Fichier absent : il est créé normalement. Coché, le mode de génération est masqué et vaut Dom4J ; DTD et XSL ne sont pas ajoutées. Reads the existing file again and adds the rows to it: a row whose group already exists joins this group, the others create their own (see the example). The tree must have a group element: without it, the job stops (see the errors). Missing file: it is created normally. Checked, the generation mode is hidden and is Dom4J; DTD and XSL are not added.
Générer un fichier compactGenerate compact filePRETTY_COMPACT NonNo ToujoursAlways Le document tient sur une ligne, après la déclaration, sans indentation (voir les exemples). Décoché, il est indenté de deux espaces. The document fits on one line, after the declaration, without indentation (see the examples). Unchecked, it is indented by two spaces.
Inclure les DTD ou XSLInclude DTD or XSLFILE_VALID NonNo ToujoursAlways Ajoute, après la déclaration, une déclaration <!DOCTYPE> ou une instruction <?xml-stylesheet?>. Le fichier n'est pas validé : seule la référence est écrite (voir l'exemple). Adds, after the declaration, a <!DOCTYPE> declaration or an <?xml-stylesheet?> instruction. The file is not validated: only the reference is written (see the example).
DTD · Élément racineRoot Element · Nom de fichierFile NameDTD_VALID · DTD_NAME · DTD_SYSTEMID choisiselected · "Root" · "Talend.dtd" DTD ou XSL cochéDTD or XSL checked Bouton radio DTD du Mode de validation : écrit <!DOCTYPE racine SYSTEM "fichier">. Donnez comme élément racine le nom de la racine de l'arbre. DTD radio button of the Validation Mode: writes <!DOCTYPE root SYSTEM "file">. Give the name of the root of the tree as root element.
XSL · Type · HrefXSL_VALID · XSL_TYPE · XSL_HREF non choisinot selected · "text/xsl" · "Talend.xsl" DTD ou XSL cochéDTD or XSL checked Bouton radio XSL : écrit <?xml-stylesheet … ?> avec le type et l'adresse de la feuille de style. En mode rapide, l'instruction n'est pas fermée correctement (voir les erreurs). XSL radio button: writes <?xml-stylesheet … ?> with the type and the address of the stylesheet. In fast mode, the instruction is not closed correctly (see the errors).

Paramètres avancésAdvanced settings

ParamètreSetting DéfautDefault VisibleShown Description
Diviser la sortie en plusieurs fichiersSplit output in several filesSPLIT NonNo Flux décochéStream unchecked Écrit plusieurs fichiers complets, numérotés à partir de 0 avant l'extension : part.xml donne part0.xml, part1.xml… Le fichier sans numéro n'est pas écrit (voir l'exemple). Writes several whole files, numbered from 0 before the extension: part.xml gives part0.xml, part1.xml… The file without a number is not written (see the example).
Lignes dans chaque fichier de sortieRows in each output fileSPLIT_EVERY 1000 Diviser cochéSplit checked Nombre de lignes par fichier ; le dernier reçoit le reste. D'après le modèle, un groupe coupé par la limite recommence dans le fichier suivant. Number of rows per file; the last one gets the rest. Per the template, a group cut by the limit starts again in the next file.
Supprimer les espaces en début et fin des donnéesTrim dataTRIM NonNo Mode Dom4JDom4J mode Enlève les espaces au début et à la fin du texte des éléments et réduit à un seul les espaces intérieurs (voir les exemples). Removes the spaces at the start and end of the element text and reduces the inner spaces to one (see the examples).
Créer le répertoire s'il n'existe pasCreate directory if it does not existCREATE OuiYes Flux décochéStream unchecked Crée le dossier du fichier, avec ses parents, quand le fichier n'existe pas (les dossiers des exemples de découpage ont été créés ainsi). Creates the folder of the file, with its parents, when the file does not exist (the folders of the split examples were created this way).
Créer un élément vide si nécessaireCreate empty element if neededCREATE_EMPTY_ELEMENT OuiYes ToujoursAlways Coché, un élément lié à une colonne null est écrit vide. Décoché, il disparaît, comme tout élément resté sans contenu ni attribut (voir les exemples). Checked, an element linked to a null column is written empty. Unchecked, it disappears, like any element left without content or attribute (see the examples).
Créer un attribut même si sa valeur est NULL.Create attribute even if its value is NULLADD_EMPTY_ATTRIBUTE NonNo ToujoursAlways Un attribut lié à une colonne null est écrit vide (city="") au lieu d'être omis. An attribute linked to a null column is written empty (city="") instead of being left out.
Créer un attribut même s'il n'est pas mappé.Create attribute even if it is unmappedADD_UNMAPPED_ATTRIBUTE NonNo ToujoursAlways Un attribut de l'arbre sans colonne ni valeur fixe est écrit vide (vip="") au lieu d'être omis. A tree attribute with neither column nor fixed value is written empty (vip="") instead of being left out.
Crée le fichier XSD associéCreate associated XSD fileOUTPUT_AS_XSD NonNo Flux décochéStream unchecked Écrit un schéma XSD de l'arbre à côté du fichier, sous le même nom avec l'extension .xsd, et le référence dans la racine (xsi:noNamespaceSchemaLocation). Les éléments vides sont alors gardés (voir l'exemple). Writes an XSD schema of the tree next to the file, under the same name with the .xsd extension, and references it in the root (xsi:noNamespaceSchemaLocation). Empty elements are then kept (see the example).
Ajouter un type Document comme nœudAdd Document type as nodeADD_DOCUMENT_AS_NODE NonNo Mode Dom4J ou écriture à la suiteDom4J mode or append Une colonne Document liée à un élément y est insérée comme des nœuds XML. Décoché, son XML est écrit comme du texte, échappé (voir l'exemple). A Document column linked to an element is inserted there as XML nodes. Unchecked, its XML is written as text, escaped (see the example).
Séparateur avancé (pour les nombres)Advanced separator (for numbers)ADVANCED_SEPARATOR NonNo ToujoursAlways Écrit les colonnes numériques avec les séparateurs choisis ci-dessous (voir les exemples). Writes the number columns with the separators chosen below (see the examples).
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.
Mode de générationGeneration modeGENERATION_MODE Lent et consommateur de mémoire (Dom4J)Slow and memory-consuming (Dom4J) Écriture à la suite décochée, ou flux cochéAppend unchecked, or stream checked Voir les modes de génération. L'autre choix est « Rapide avec peu de consommation de mémoire ». See the generation modes. The other choice is “Fast with low memory consumption”.
EncodageEncodingENCODING "ISO-8859-15" ToujoursAlways L'encodage du fichier, aussi écrit dans la déclaration (voir l'exemple). The file encoding, also written in the declaration (see the example).
Ne pas générer de fichier videDon't generate empty fileDELETE_EMPTYFILE NonNo Flux décochéStream unchecked Sans ligne reçue, le fichier est supprimé, s'il n'existait pas avant l'exécution. Un fichier déjà présent est vidé, pas supprimé (voir les exemples). With no row received, the file is deleted, if it did not exist before the run. A file already there is emptied, not deleted (see the examples).

Variable globaleGlobal variable

NB_LINE (Integer, disponible après l'exécution du composant) : nombre de lignes reçues, tous fichiers confondus avec Diviser la sortie. NB_LINE (Integer, available after the component has run): number of rows received, all files together with Split output.

((Integer) globalMap.get("tAdvancedFileOutputXML_1_NB_LINE"))

ExemplesExamples

Un tFixedFlowInput envoie les lignes au tAdvancedFileOutputXML. Les fichiers sont écrits sous C:/data/xml/ (le dossier de travail est remplacé ici par C:/data). Un tJava relié par On Subjob Ok affiche ensuite chaque fichier, décodé en ISO-8859-15, après une ligne --- nom (suivie de (CR LF) si le fichier contient des fins de ligne Windows). Les sorties sont copiées depuis des exécutions des jobs dans Talaxie (Java 21). A tFixedFlowInput sends the rows to the tAdvancedFileOutputXML. The files are written under C:/data/xml/ (the working folder is replaced here with C:/data). A tJava connected with On Subjob Ok then prints each file, decoded as ISO-8859-15, after a --- name line (followed by (CR LF) if the file holds Windows line ends). The outputs are copied from runs of the jobs in Talaxie (Java 21).

Réglages par défautDefault settings

row1 (Main) OnSubjobOk tFixedFlowInput_1 tAdvancedFileOutputXML_1 tJava_1
idInteger nameString cityString
1AdaLondon
2AlanLondon
3GraceNew York

Nom de fichier "C:/data/xml/customers.xml". Arbre : File name "C:/data/xml/customers.xml". Tree:

customers
└─ customer            boucleloop
   ├─ @id              ← id
   ├─ name             ← name
   └─ city             ← city
--- xml/customers.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
  <customer id="1">
    <name>Ada</name>
    <city>London</city>
  </customer>
  <customer id="2">
    <name>Alan</name>
    <city>London</city>
  </customer>
  <customer id="3">
    <name>Grace</name>
    <city>New York</city>
  </customer>
</customers>
tAdvancedFileOutputXML_1_NB_LINE: 3

Un seul document, indenté de deux espaces, avec une ligne vide après la déclaration. A single document, indented by two spaces, with an empty line after the declaration.

Élément de groupeGroup element

Mêmes lignes. Arbre : customers › city en élément de groupe, attribut name ← city › customer en boucle (@id, name). Same rows. Tree: customers › city as group element, name attribute ← city › customer as loop (@id, name).

--- xml/group.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
  <city name="London">
    <customer id="1">
      <name>Ada</name>
    </customer>
    <customer id="2">
      <name>Alan</name>
    </customer>
  </city>
  <city name="New York">
    <customer id="3">
      <name>Grace</name>
    </customer>
  </city>
</customers>

Avec les lignes dans l'ordre London, New York, London, le fichier a trois éléments city, dont deux London : un groupe commence à chaque changement de valeur. Triez d'abord le flux. With the rows in the order London, New York, London, the file has three city elements, two of them London: a group starts at each change of value. Sort the flow first.

Fichier compact, mode rapideCompact file, fast mode

Le même arbre de groupe, écrit avec Générer un fichier compact, en Dom4J puis en mode rapide : The same group tree, written with Generate compact file, in Dom4J then in fast mode:

--- xml/compact.xml
<?xml version="1.0" encoding="ISO-8859-15"?>
<customers><city name="London"><customer id="1"><name>Ada</name></customer><customer id="2"><name>Alan</name></customer></city><city name="New York"><customer id="3"><name>Grace</name></customer></city></customers>
--- xml/null_compact.xml (CR LF)
<?xml version="1.0" encoding="ISO-8859-15"?>
<customers><city name="London"><customer id="1"><name>Ada</name></customer><customer id="2"><name>Alan</name></customer></city><city name="New York"><customer id="3"><name>Grace</name></customer></city></customers>

Sans compact, le mode rapide a écrit le même texte que Dom4J (exemple précédent), mais avec des fins de ligne mêlées : \r\n après la déclaration et après certaines balises fermantes, \n ailleurs, et aucune après la dernière balise. Le mode Dom4J n'écrit que des \n. Without compact, the fast mode wrote the same text as Dom4J (previous example), but with mixed line ends: \r\n after the declaration and after some closing tags, \n elsewhere, and none after the last tag. The Dom4J mode only writes \n.

Diviser la sortieSplit output

Cinq lignes (Ada, Grace, Alan, Margaret, Edsger), nom de fichier "C:/data/xml/split5/part.xml", Diviser la sortie coché, 2 lignes par fichier. Le tJava affiche les fichiers du dossier (les deux premiers abrégés) : Five rows (Ada, Grace, Alan, Margaret, Edsger), file name "C:/data/xml/split5/part.xml", Split output checked, 2 rows per file. The tJava prints the files of the folder (the first two shortened):

--- xml/split5/part0.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
  <customer id="1">
…
--- xml/split5/part1.xml
…
--- xml/split5/part2.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
  <customer id="5">
    <name>Edsger</name>
    <city>Rotterdam</city>
  </customer>
</customers>
tAdvancedFileOutputXML_1_NB_LINE: 5

Chaque fichier est un document complet. Avec quatre lignes, Dom4J a écrit deux fichiers ; le mode rapide en laisse un troisième, vide (voir les erreurs). Each file is a whole document. With four rows, Dom4J wrote two files; the fast mode leaves a third one, empty (see the errors).

Écrire à la suiteAppend

Arbre de groupe. Un premier sous-job écrit 1|Ada|London et 3|Grace|New York ; un second, avec Écrire les données à la fin du fichier XML source, ajoute 2|Alan|London et 4|Margaret|Boston au même fichier : Group tree. A first subjob writes 1|Ada|London and 3|Grace|New York; a second one, with Append the source xml file, adds 2|Alan|London and 4|Margaret|Boston to the same file:

--- xml/append_group.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
  <city name="London">
    <customer id="1">
      <name>Ada</name>
    </customer>
    <customer id="2">
      <name>Alan</name>
    </customer>
  </city>
  <city name="New York">
    <customer id="3">
      <name>Grace</name>
    </customer>
  </city>
  <city name="Boston">
    <customer id="4">
      <name>Margaret</name>
    </customer>
  </city>
</customers>

Alan rejoint le groupe London déjà écrit ; Boston, absent, crée son groupe en fin de document. Alan joins the London group already written; Boston, missing, creates its group at the end of the document.

DTD ou feuille XSLDTD or XSL stylesheet

Une ligne, Inclure les DTD ou XSL coché. dtd.xml : DTD, élément racine "customers", fichier "customers.dtd". xsl.xml : XSL, type "text/xsl", href "customers.xsl". Début des fichiers : One row, Include DTD or XSL checked. dtd.xml: DTD, root element "customers", file "customers.dtd". xsl.xml: XSL, type "text/xsl", href "customers.xsl". Start of the files:

--- xml/dtd.xml
<?xml version="1.0" encoding="ISO-8859-15"?>
<!DOCTYPE customers SYSTEM "customers.dtd">

<customers>
…
--- xml/xsl.xml
<?xml version="1.0" encoding="ISO-8859-15"?>
<?xml-stylesheet href="customers.xsl" type="text/xsl"?>

<customers>
…

Le mode rapide écrit la même déclaration DOCTYPE ; son instruction xml-stylesheet est fautive (voir les erreurs). The fast mode writes the same DOCTYPE declaration; its xml-stylesheet instruction is faulty (see the errors).

Valeurs absentesMissing values

Colonnes id, name, city, note. Lignes 1|Ada|London|null et 2|Alan|null|call back. Arbre : customer en boucle avec les attributs id, city et vip (sans colonne), les éléments name et note. Quatre fichiers : par défaut, Créer un attribut même si sa valeur est NULL., Créer un attribut même s'il n'est pas mappé., Créer un élément vide si nécessaire décoché. Columns id, name, city, note. Rows 1|Ada|London|null and 2|Alan|null|call back. Tree: customer as loop with the attributes id, city and vip (no column), the elements name and note. Four files: default, Create attribute even if its value is NULL, Create attribute even if it is unmapped, Create empty element if needed unchecked.

--- xml/empty_default.xml
…
  <customer id="1" city="London">
    <name>Ada</name>
    <note/>
  </customer>
  <customer id="2">
    <name>Alan</name>
    <note>call back</note>
  </customer>
…
--- xml/empty_attr.xml
…
  <customer id="1" city="London">
…
  <customer id="2" city="">
…
--- xml/empty_unmapped.xml
…
  <customer id="1" city="London" vip="">
…
  <customer id="2" vip="">
…
--- xml/empty_noelem.xml
…
  <customer id="1" city="London">
    <name>Ada</name>
  </customer>
…

Le mode rapide, avec les deux cases d'attributs cochées, a écrit city="" vip="" de la même façon, et <note></note> pour l'élément vide. The fast mode, with both attribute boxes checked, wrote city="" vip="" the same way, and <note></note> for the empty element.

Aucune ligneNo row

Le tFixedFlowInput n'envoie aucune ligne. norow.xml : réglages par défaut ; norow_delete.xml : Ne pas générer de fichier vide ; norow_null.xml : mode rapide ; norow_old.xml : Ne pas générer de fichier vide, sur un fichier écrit juste avant par un tJava (<old/>). The tFixedFlowInput sends no row. norow.xml: default settings; norow_delete.xml: Don't generate empty file; norow_null.xml: fast mode; norow_old.xml: Don't generate empty file, on a file written just before by a tJava (<old/>).

--- xml/norow.xml: empty file
--- xml/norow_delete.xml: missing
--- xml/norow_null.xml (CR LF)
<?xml version="1.0" encoding="ISO-8859-15"?>
--- xml/norow_old.xml: empty file
tAdvancedFileOutputXML_1_NB_LINE: 0

Sans ligne, Dom4J laisse un fichier de 0 octet, qu'un lecteur XML refuse, et le mode rapide la seule déclaration. Le fichier qui existait déjà est vidé : son ancien contenu est perdu, mais il n'est pas supprimé. With no row, Dom4J leaves a 0-byte file, which an XML reader rejects, and the fast mode only the declaration. The file that already existed is emptied: its old content is lost, but it is not deleted.

Fichier XSD associéAssociated XSD file

Arbre de groupe, lignes Ada et Alan, nom de fichier "C:/data/xml/xsd/customers.xml", Crée le fichier XSD associé coché. Le dossier contient ensuite (XSD abrégé) : Group tree, rows Ada and Alan, file name "C:/data/xml/xsd/customers.xml", Create associated XSD file checked. The folder then holds (XSD shortened):

--- xml/xsd/customers.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="customers.xsd">
  <city name="London">
…
--- xml/xsd/customers.xsd
<?xml version="1.0" encoding="ISO-8859-15"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="customers" nillable="true">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="city" nillable="true" minOccurs="0" maxOccurs="unbounded">
…
            <xsd:attribute name="name"/>
…

La référence est le seul nom du fichier XSD, relatif au document. Le schéma décrit la forme de l'arbre, sans types. En mode rapide, le XSD n'a pas de déclaration XML. The reference is the bare name of the XSD file, relative to the document. The schema describes the shape of the tree, without types. In fast mode, the XSD has no XML declaration.

Flux de sortieOutput stream

Lignes Ada et Alan, Utiliser le flux de sortie coché, Flux de sortie System.out : le document va dans la console. Dom4J, puis mode rapide, puis un tJava qui affiche === end : Rows Ada and Alan, Use Output Stream checked, Output Stream System.out: the document goes to the console. Dom4J, then fast mode, then a tJava that prints === end:

=== Dom4j
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
…
</customers>
=== Null
<?xml version="1.0" encoding="ISO-8859-15"?>

<customers>
…
  <customer id="2">
    <name>Alan</name>
    <city>London</city>
  </customer>
</customers>=== end

Le flux reste ouvert et utilisable après le composant. Le mode rapide ne finit pas par un saut de ligne : la sortie suivante se colle à la dernière balise. The stream stays open and usable after the component. The fast mode does not end with a line break: the next output sticks to the last tag.

Colonne DocumentDocument column

Colonne detail de type Document, valeur ParserUtils.parseTo_Document("<order id=\"7\"><item>pen</item></order>"), liée à l'élément detail. Réglages par défaut, puis Ajouter un type Document comme nœud : detail column of type Document, value ParserUtils.parseTo_Document("<order id=\"7\"><item>pen</item></order>"), linked to the detail element. Default settings, then Add Document type as node:

--- xml/doc_text.xml
…
    <name>Ada</name>
    <detail>&lt;order id="7"&gt;&lt;item&gt;pen&lt;/item&gt;&lt;/order&gt;</detail>
…
--- xml/doc_node.xml
…
    <name>Ada</name>
    <detail>
      <order id="7">
        <item>pen</item>
      </order>
    </detail>
…

En mode rapide, où la case n'existe pas, le document est écrit comme du texte, déclaration XML comprise : &lt;?xml version=&quot;1.0&quot; …. In fast mode, where the box does not exist, the document is written as text, XML declaration included: &lt;?xml version=&quot;1.0&quot; ….

Supprimer les espacesTrim data

Ligne 1, " Ada Lovelace ", " London ", sans puis avec Supprimer les espaces en début et fin des données : Row 1, " Ada Lovelace ", " London ", without then with Trim data:

--- xml/notrim.xml
…
    <name>  Ada   Lovelace  </name>
    <city> London </city>
…
--- xml/trim.xml
…
    <name>Ada Lovelace</name>
    <city>London</city>
…

Nombres et datesNumbers and dates

Colonnes n (Integer) = 1234567, amount (BigDecimal, précision 2) = 1234567.456, rate (Double) = 0.5, day (Date, modèle "yyyy-MM-dd") = 11/11/2026 9 h 30, flag (Boolean) = true. Par défaut, puis avec Séparateur avancé ("." pour les milliers, "," pour les décimales) : Columns n (Integer) = 1234567, amount (BigDecimal, precision 2) = 1234567.456, rate (Double) = 0.5, day (Date, pattern "yyyy-MM-dd") = 2026-11-11 9:30, flag (Boolean) = true. Default, then with Advanced separator ("." for thousands, "," for decimals):

--- xml/types.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<values>
  <value n="1234567">
    <amount>1234567.46</amount>
    <rate>0.5</rate>
    <day>2026-11-11</day>
    <flag>true</flag>
  </value>
</values>
--- xml/types_sep.xml
<?xml version="1.0" encoding="ISO-8859-15"?>

<values>
  <value n="1.234.567">
    <amount>1.234.567,46</amount>
    <rate>0,5</rate>
    <day>2026-11-11</day>
    <flag>true</flag>
  </value>
</values>

La précision de la colonne BigDecimal arrondit la valeur (au plus proche, 0,5 vers le haut) : 1234567.456 devient 1234567.46. Le séparateur avancé touche aussi les attributs numériques. The precision of the BigDecimal column rounds the value (to the nearest, 0.5 upwards): 1234567.456 becomes 1234567.46. The advanced separator also changes the number attributes.

EncodageEncoding

Ligne 1|Café|Zürich, écrite avec l'encodage par défaut (latin.xml), puis "UTF-8" en Dom4J (utf8.xml) et en mode rapide (utf8_null.xml). Le tJava affiche la déclaration, les octets de name en hexadécimal et la présence de fins de ligne CR LF : Row 1|Café|Zürich, written with the default encoding (latin.xml), then "UTF-8" in Dom4J (utf8.xml) and in fast mode (utf8_null.xml). The tJava prints the declaration, the bytes of name in hexadecimal and whether there are CR LF line ends:

latin.xml: <?xml version="1.0" encoding="ISO-8859-15"?>
  <name>: 43 61 66 E9, CR LF: false
utf8.xml: <?xml version="1.0" encoding="UTF-8"?>
  <name>: 43 61 66 C3 A9, CR LF: false
utf8_null.xml: <?xml version="1.0" encoding="UTF-8"?>
  <name>: 43 61 66 C3 A9, CR LF: true

Erreurs et piègesErrors and pitfalls

Mêmes jobs que dans les exemples. Le nom du job est remplacé par MyJob et les traces d'exception sont abrégées. Same jobs as in the examples. The job name is replaced with MyJob and the exception traces are shortened.

Écrire à la suite sans élément de groupeAppend without a group element

Arbre des exemples (boucle, sans groupe). Un premier sous-job écrit le fichier, un second y ajoute deux lignes avec Écrire les données à la fin du fichier XML source : le job s'arrête (code 1). Tree of the examples (loop, no group). A first subjob writes the file, a second one adds two rows to it with Append the source xml file: the job stops (exit code 1).

Exception in component tAdvancedFileOutputXML_2 (MyJob)
java.lang.NullPointerException: Cannot invoke "org.dom4j.Element.elements()" because "<local32>" is null
	at …MyJob.tFixedFlowInput_2Process(MyJob.java:2118)
	…

En écriture à la suite, le code généré ne retrouve l'endroit où insérer qu'à partir d'un élément de groupe ; l'éditeur le rappelle (Requiert au moins un groupe et une boucle.). Ajoutez un élément de groupe au-dessus de la boucle (voir l'exemple). Le texte du message est celui de Java 21. When appending, the generated code only finds the place to insert from a group element; the editor reminds it (Require set as loop and set as group at least.). Add a group element above the loop (see the example). The text of the message is the Java 21 one.

Colonne Date sans modèle : le job ne compile pasDate column without pattern: the job does not compile

Colonne created de type Date, modèle de date effacé dans le schéma, liée à un élément. Le compilateur Java refuse le code généré : created column of type Date, date pattern cleared in the schema, linked to an element. The Java compiler rejects the generated code:

MyJob.java:977: error: incompatible types: bad type in conditional expression
			row1.created:null
			    ^
    Date cannot be converted to String
1 error

Sans modèle, le modèle du composant range la date elle-même là où il attend un texte (défaut de tAdvancedFileOutputXML_begin.inc.javajet). Gardez un modèle de date sur chaque colonne Date, comme celui que le Studio propose à la création de la colonne. Without a pattern, the template of the component stores the date itself where it expects a text (defect of tAdvancedFileOutputXML_begin.inc.javajet). Keep a date pattern on each Date column, like the one the Studio proposes when the column is created.

Feuille XSL en mode rapide : instruction non ferméeXSL stylesheet in fast mode: instruction not closed

Réglages de xsl.xml (voir l'exemple), mode rapide : Settings of xsl.xml (see the example), fast mode:

--- xml/xsl_null.xml (CR LF)
<?xml version="1.0" encoding="ISO-8859-15"?>
<?xml-stylesheet type="text/xsl" href="customers.xsl">

<customers>
…

L'instruction finit par > au lieu de ?> : le fichier n'est pas un XML bien formé (défaut du modèle, tAdvancedFileOutputXML_begin.javajet et _main.javajet). Utilisez le mode Dom4J pour une feuille XSL. The instruction ends with > instead of ?>: the file is not well-formed XML (defect of the template, tAdvancedFileOutputXML_begin.javajet and _main.javajet). Use the Dom4J mode for an XSL stylesheet.

Découpage en mode rapide : un fichier vide de tropSplit in fast mode: one empty file too many

Quatre lignes, 2 par fichier, mode rapide, nom de fichier "C:/data/xml/split4null/part.xml" : Four rows, 2 per file, fast mode, file name "C:/data/xml/split4null/part.xml":

--- xml/split4null/part0.xml
…
--- xml/split4null/part1.xml
…
  <customer id="4">
    <name>Margaret</name>
    <city>Boston</city>
  </customer>
</customers>
--- xml/split4null/part2.xml: empty file

Quand le nombre de lignes tombe juste, le mode rapide a déjà ouvert le fichier suivant et ne l'écrit jamais : il reste un fichier de 0 octet. Le mode Dom4J ne le crée pas. When the number of rows divides exactly, the fast mode has already opened the next file and never writes it: a 0-byte file remains. The Dom4J mode does not create it.

Conseils et limitesTips and limits

Encodage : UTF-8 de préférenceEncoding: UTF-8 preferably

Le défaut, ISO-8859-15, est bien déclaré dans le fichier, mais un lecteur XML n'est tenu de connaître que UTF-8 et UTF-16. Choisissez "UTF-8" dès que le fichier sort du job. The default, ISO-8859-15, is declared in the file, but an XML reader is only required to know UTF-8 and UTF-16. Choose "UTF-8" as soon as the file leaves the job.

Gros volumesLarge volumes

En Dom4J, tout le document reste en mémoire jusqu'à la fin du flux (ou du fichier, avec Diviser la sortie). Pour des millions de lignes, prenez le mode rapide, ou découpez la sortie ; l'écriture à la suite relit aussi tout le fichier existant en mémoire. In Dom4J, the whole document stays in memory until the end of the flow (or of the file, with Split output). For millions of rows, take the fast mode, or split the output; appending also reads the whole existing file into memory.

Espaces de nomsNamespaces

Un espace de noms par défaut et un espace préfixé sur la racine, avec un élément x:city, ont donné le même fichier dans les deux modes : <customers xmlns="http://example.com/crm" xmlns:x="http://example.com/extra">, puis <x:city>London</x:city>. Le tWriteXMLField, lui, échoue sur ce cas en Dom4J. A default namespace and a prefixed one on the root, with an x:city element, gave the same file in both modes: <customers xmlns="http://example.com/crm" xmlns:x="http://example.com/extra">, then <x:city>London</x:city>. The tWriteXMLField fails on this case in Dom4J.

Vérifier le fichierChecking the file

Le composant ne valide rien, même avec une DTD ou un XSD. Pour contrôler le fichier écrit, enchaînez un tXSDValidator ou un tDTDValidator par On Subjob Ok. The component validates nothing, even with a DTD or an XSD. To check the written file, chain a tXSDValidator or a tDTDValidator with On Subjob Ok.

Voir aussiSee also