Wie sieht mein Script aus? Mein XML sieht etwas anders aus als das Beispiel.
So?
<#assign row = target.addRow()>
<#list xml[„OFFERS“][„GROUP“][„O“] as art>
<#assign row = target.addRow()>
${row.addCol(„Artikelnummer“,art[„id“])}
${row.addCol(„Availability“,art[„avail“])}
</#list>
Sollte bei dir folgendermaßen aussehen: <#ftl ns_prefixes={"xsi":"https://www.w3.org/2001/XMLSchema-instance"} >
Das parsing template sollte ungefähr so aussehen:
<#ftl ns_prefixes={"xsi":"https://www.w3.org/2001/XMLSchema-instance"} >
<#assign row = target.addRow()>
<#list xml["offers"]["group"]["o"] as art> <#-- Groß- / Kleinschreibung wird beachtet -->
<#assign row = target.addRow()>
${row.addCol("Artikelnummer", attr("id", art))!} <#-- attribute id an o Element -->
${row.addCol("Availability", art["avail"]!)} <#-- sieht man im Screenshot leider nicht -->
</#list>
Danke, das hat funktioniert!
Jetzt brauche ich noch einen Wert aus einem anderen Bereich.
Wie greife ich darauf zu? Ich kann es leider nicht ableiten aus Deiner Lösung.
@synesty-Torsten danke für Deine Antwort.
Leider bekomme ich einen Fehler (siehe unten)
Ich habe die Namen der Variablen angepasst gemäß des XML Files (siehe screenshot).
Mit Deinem Code kam der gleiche Fehler. Verstehe leider nicht, was hier das Problem ist.
<#ftl ns_prefixes={"xsi":"https://www.w3.org/2001/XMLSchema-instance"} >
<#assign row = target.addRow()>
<#list xml["offers"]["group"]["o"] as art> <#-- Groß- / Kleinschreibung wird beachtet -->
<#assign row = target.addRow()>
${row.addCol("Artikelnummer", attr("id", art))!} <#-- attribute id an o Element -->
${row.addCol("Stock", attr("stock",art))!} <#-- sieht man im Screenshot leider nicht -->
<#list art["a"] as a>
<#if a["name"]! == "Kod producenta">
${row.addCol("Kod producenta", a["CDATA"]!)}
</#if>
</#list>
</#list>
Fehler beim Parsing der 2. Datei service_new.xml. In den meisten Fällen ist die Datei leer, kaputt oder ist inhaltlich fehlerhaft, so dass Sie nicht geparst werden kann. (Root Causes: RuntimeException: NonStringException: For „==“ left-hand operand: Expected a string or something automatically convertible to string (number, date or boolean), but this has evaluated to a sequence+hash (wrapper: f.e.dom.NodeListModel): ==> a[„name“]! [in template „xmlToSpreadsheet“ at line 9, column 8] ---- FTL stack trace („~“ means nesting-related): - Failed at: #if a[„name“]! == „Kod producenta“ [in template „xmlToSpreadsheet“ at line 9, column 3] ---- NonStringException: For „==“ left-hand operand: Expected a string or something automatically convertible to string (number, date or boolean), but this has evaluated to a sequence+hash (wrapper: f.e.dom.NodeListModel): ==> a[„name“]! [in template „xmlToSpreadsheet“ at line 9, column 8] ---- FTL stack trace („~“ means nesting-related): - Failed at: #if a[„name“]! == „Kod producenta“ [in template „xmlToSpreadsheet“ at line 9, column 3] ----)
anhand des Screenshot davor war mir nicht klar das „name“ ein Attribut von a ist. Das ist vermutlich auch das Problem. Kannst du bitte den Teil nochmal etwas anpassen:
<#list art["a"] as a>
<#if attr("name", a)! == "Kod producenta">
${row.addCol("Kod producenta", a!)}
</#if>
</#list>