2017-09-22 7 views
0

Ce que j'essaie d'accomplir est: Je veux mettre à jour automatiquement 10.000 prix dans mon indesign catalogue. La seule façon de faire cela est d'utiliser XML. Lorsque j'étiquette les cellules de mon tableau dans indesign, je peux exporter un fichier XML qui ressemble à ceci.Trouver et remplacer le contenu entre les balises XML d'un autre fichier

-<Root> 
-<Artikel> 
-<Tabel aid:tcols="5" aid:trows="6" aid:table="table" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"> 
<Cel aid:table="cell" aid:ccols="5" aid:crows="1">.: Rollerflam </Cel> 
<Cel aid:table="cell" aid:ccols="5" aid:crows="1"/> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="79.29730708729332"/> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="65.97828346376967">Artikel code</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="144.56692913385828">Omschrijving</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="42.519685039370074">Prijs/st.</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="34.01574803149606">PG</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="3" aid:ccolwidth="79.29730708729332"/> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="65.97828346376967">AIRK7274</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="144.56692913385828">Rollerflampost </Cel> 
-<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="42.519685039370074"> 

<AIRK7274>717,00</AIRK7274> 

</Cel> 

<Cel aid:table="cell" aid:ccols="1" aid:crows="3" aid:ccolwidth="34.01574803149606">-</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="65.97828346376967">AIRK7275</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="144.56692913385828">Rollerflampost met lastoebehoren</Cel> 
+<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="42.519685039370074"> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="65.97828346376967">AIRK7277</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="144.56692913385828">Rollerflampost +las-en snijtoebehoren</Cel> 
-<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="42.519685039370074"> 

<AIRK7277>1055,00</AIRK7277> 

</Cel> 
</Tabel> 
</Artikel> 

-<Artikel> 
-<Tabel aid:tcols="5" aid:trows="7" aid:table="table" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"> 
<Cel aid:table="cell" aid:ccols="5" aid:crows="1">.: Junior flessen </Cel> 
<Cel aid:table="cell" aid:ccols="5" aid:crows="1"/> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="79.29730708729332"/> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="65.97828346376964">Artikel code</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="144.56692913385828">Omschrijving</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="42.519685039370074">Prijs/st.</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="34.01574803149606">PG</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="79.29730708729332"/> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="65.97828346376964">AIRK7272</Cel> 
<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="144.56692913385828">Fles met vulling van 2.30m³ zuurstof</Cel> 
-<Cel aid:table="cell" aid:ccols="1" aid:crows="1" aid:ccolwidth="42.519685039370074"> 

<AIRK7272>345,00</AIRK7272> 

</Cel> 

Ce ne sont que quelques articles. Maintenant, j'ai une liste de tous ces articles avec des étiquettes qui ressemble à ce

<AIRK7274>222</AIRK7274> 
<AIRK7275>222</AIRK7275> 
<AIRK7277>1055</AIRK7277> 
<AIRK7272>345</AIRK7272> 
<AIRK7271>309</AIRK7271> 
<AIRK7276>310</AIRK7276> 
<AIRK7270>310</AIRK7270> 
<AIR01150>42</AIR01150> 
<AIR02150>42</AIR02150> 
<AIR08193>42</AIR08193> 
<AIR08197>42</AIR08197> 
<AIR73142>39,5</AIR73142> 
<AIRK7250>291</AIRK7250> 
<AIRK7280>435</AIRK7280> 
<BI1410>15,746</BI1410> 

Est-il possible de remplacer le contenu entre les balises XML du fichier indesign avec le contenu de mon dossier? J'ai lu à propos de XML parser et regex mais je ne comprends pas encore vraiment. Quelqu'un pourrait-il essayer de me donner une bonne explication à ce sujet et me dire si c'est possible ce que j'essaie d'accomplir? Merci beaucoup d'avance!

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
+0

Oui, c'est possible dans le cas général. Cependant, spécifiez quelle langue utilisez-vous pour le traitement XML. –

+0

Je pense que vous voulez dire cette ligne Christophe

Répondre

0

@loic

Je pense que je l'ai trouvé la réponse. Je enlevé

xe.contents = String(Number (String(tag).replace (/,/g, "."))*2).replace (/\./g, ","); 

et remplacé avec

xe.contents = String(tag).replace (/,/g, ".") .replace (/\./g, ","); 

Il semble fonctionner et problème est résolu merci Loic pour votre aide!

0

Voici une approche possible par l'accès InDesign Scripting DOM:

var main = function() { 
 
\t var doc = app.properties.activeDocument, 
 
\t root, xe, price, 
 
\t tags = <tags> 
 
<AIRK7274>222</AIRK7274> 
 
<AIRK7275>222</AIRK7275> 
 
<AIRK7277>1055</AIRK7277> 
 
<AIRK7272>345</AIRK7272> 
 
<AIRK7271>309</AIRK7271> 
 
<AIRK7276>310</AIRK7276> 
 
<AIRK7270>310</AIRK7270> 
 
<AIR01150>42</AIR01150> 
 
<AIR02150>42</AIR02150> 
 
<AIR08193>42</AIR08193> 
 
<AIR08197>42</AIR08197> 
 
<AIR73142>39,5</AIR73142> 
 
<AIRK7250>291</AIRK7250> 
 
<AIRK7280>435</AIRK7280> 
 
<BI1410>15,746</BI1410> 
 
</tags>, tag, xes; 
 
\t 
 
\t 
 
\t if (!doc) return; 
 
\t 
 
\t root = doc.xmlElements[0]; 
 
\t 
 
\t tags = tags.children(), n = tags.length(); 
 
\t 
 
\t while (n--) { 
 
\t \t tag = tags[n]; 
 
\t \t xes = root.evaluateXPathExpression (".//"+ String(tag.name())); 
 
\t \t if (xes.length) { 
 
\t \t \t xe = xes[0]; 
 
\t \t \t xe.contents = String(Number (String(tag).replace (/,/g, "."))*2).replace (/\./g, ","); 
 
\t \t } 
 
\t } 
 
} 
 

 

 
var u; 
 

 
app.doScript ("main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script");

Before script is run After Script is run. Prices get doubled…

+0

Merci beaucoup Loic! Il y a seulement une chose de plus que je voudrais accomplir et c'est d'avoir chaque prix montré avec 2 décimales. Par exemple: Lorsque le prix dit « 717,45 », il renvoie le prix dans indesign comme « 717,45 » Lorsque le prix dit « 717,00 », il renvoie le prix dans indesign comme « 717 » Quelqu'un at-il une solution pour cela? – Christophe

0

En effet, les "fois 2" était un exemple de ce vous pourriez faire. Pour nombre « rondes » en cas de besoin, ils sont bien des façons, mais une solution rapide pourrait consister à:

xe.contents = String(Number (String(tag).replace (/,/g, "."))*2).replace (/\./g, ",").replace (',00', '');

+0

Merci Loic pour votre réponse mais je pense que vous avez mal lu la question ou probablement je ne l'ai pas bien expliqué. Je ne veux pas que les prix soient arrondis. Donc quand je mets "717,00" dans le script indesign retourne "717" et non "717,00" comme je le veux. Y at-il un moyen pour indesign de retourner exactement ce que j'ai mis entre les balises? – Christophe