• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

String multilines

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am new in Grovvy, i need help to write this  script

source xml :

<?xml version="1.0" encoding="UTF-8" ?>
<root>
 <PPM_PROJECT_ID>24</PPM_PROJECT_ID>
 <SUBJECT>test API REST, impersonation Boris V3</SUBJECT>
 <STATUS>E0001</STATUS>
 <PRIORITY>1</PRIORITY>
 <TICKET_ID>TICK4</TICKET_ID>
 <PPM_WAVE>WAVE4</PPM_WAVE>
 <TICKET_GUID>GUID4</TICKET_GUID>
 <assigned_to>367</assigned_to>
 <DESCRIPTION>Appel de création par postam. createur moi assigné Boris</DESCRIPTION>
 <custom_fields>
   <id>53</id>
   <value>BA458F85E125</value>
 </custom_fields>
 <custom_fields>
   <id>54</id>
   <value>1214</value>
 </custom_fields>
 <TEXT>
   <TEXTID>CD03</TEXTID>
   <TEXT>TEXT CD03</TEXT>
 </TEXT>
 <TEXT>
   <TEXTID>S115</TEXTID>
   <TEXT>TEXT S115</TEXT>
 </TEXT>
 <TEXT>
   <TEXTID>CD04</TEXTID>
   <TEXT>TEXT CD04</TEXT>
 </TEXT>
 <TEXT>
   <TEXTID>CR01</TEXTID>
   <TEXT>TEXT CR01</TEXT>
 </TEXT>
 <DOCUMENT>
   <FILENAME>DOCUMENT1.DOC</FILENAME>
   <URL>https://dsi-sta-lci1.interne.ugap.fr:8001</URL>;
 </DOCUMENT>
 <DOCUMENT>
   <FILENAME>DOCUMENT2.PDF</FILENAME>
   <URL>https://dsi-sta-lci1.interne.ugap.fr:8002</URL>;
 </DOCUMENT>
 <ATTACHMENT>
   <FILENAME>ATTACHEMENT1.DOC</FILENAME>
   <URL>https://dsi-sta-lci1.interne.ugap.fr:8003</URL>;
 </ATTACHMENT>
 <ATTACHMENT>
   <FILENAME>ATTACHEMENT2.PDF</FILENAME>
   <URL>https://dsi-sta-lci1.interne.ugap.fr:8004</URL>;
 </ATTACHMENT>
 <PROCESS_STRUCT>
   <PROCESS_TYPE>S1TM</PROCESS_TYPE>
   <DESCRIPTION>PROCESSUS1</DESCRIPTION>
   <URL>URL1 OF PROCESSUS1</URL>
   <DESCRIPTION>PROCESSUS2</DESCRIPTION>
   <URL>URL2 OF PROCESSUS2</URL>
 </PROCESS_STRUCT>
</root>

requirement: read the <PROCESS_STRUCT> tag and write the result to a string variable in the following format:

processus:\r\n\r\n*\"[PROCESS_STRUCT][1]-DESCRIPTION":\"[PROCESS_STRUCT][1]-URL\r\n*\"[PROCESS_STRUCT][2]-DESCRIPTION":\"[PROCESS_STRUCT][2]-URL\r\n*\"[PROCESS_STRUCT][n]-DESCRIPTION":\"[PROCESS_STRUCT][n]-URL\r\n\r\n

I tried this,
def String long_process = "processus:"
for (def text : root.PROCESS_STRUCT) {

            description = "";
            url = "";
description = text.DESCRIPTION;
url = text.URL;

            long_process = long_process   + "\n" + description  + ":" + url;

but the result is not correct:
processus:
PROCESSUS1PROCESSUS2:URL1 PROCESSUS1URL2 PROCESSUS2

Best regards
 
Marshal
Posts: 8132
572
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think anyone going to write the code for you, that looks like a professional business problem to solve.

Anyway, you never explained the rules to anyone, from the given example isn't very obvious.

For instance:
1. Why <PROCESS_TYPE> is not in an output, i.e. "[PROCESS_STRUCT][1]-PROCESS_TYPE"
2. What is the logic behind the "[PROCESS_STRUCT][n]-UR" being in an output

As you see, things aren't clear, well, at least for me.

So you need to put some effort at least in explaining problem a bit more, so somebody might become interested actually tacking this problem together with you.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic