• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to update xml tag values by groovy

 
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get xml content then update it and send it back to it's original place, but evry time i run my code it seems that extra characters are added ('\r' and '\n') with this updated data and as a result it increases file size , how can i remove this characters?  When  i try to  update  my  xml   at   first  time  it  changes  xml  tag  values  but  on  the  other  attempts it  neither  trows  exception nor updates  data,  is  it  because  that  this  '\n'  are changing  position  xml tag  values?  :
[code=groovy]def xml = new XmlParser().parseText(content)
           for(int i=0;i<value.size();i++) {
               date = value.get(i).substring(0, 10);
               xml.Mr.ross.details.findAll( { p ->
                  p.runAs[0].text() == "true" &&  date.toString()== p.start[0].text();
               }).each({ p ->
                   p.start[0].value =addDays( p.start[0].text())
                   p.runAs[0].value ="true"
               })
           }

For example xml data looks like:


<?xml version="1.0" encoding="UTF-8" standalone="no"?><service>
 <Ms>
   <ross>
     <details>
       <start>
                                                                     2017-09-07                                              
       </start>
       <startDate>
                                                                     2017-02-02                                                
       </startDate>
       <endDate>
                                                                     2017-03-02                                                
       </endDate>
       <runAs>
                                                                     true                                                
       </runAs>
       <makeVersion>
                                                                     1                                                
       </makeVersion>
       <patch>
                                                                     this is  patch                                                
       </patch>
       <parameter>
                                                                     1                                                
       </parameter>
     </details>
   </ross>

 </Ms>
</service>
 
author & internet detective
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sally,
You don't show what addDays() does. Have you tried calling trim() at the end of it to get rid of extra whitespace?
 
sally tkhilaishvili
Greenhorn
Posts: 4
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes  i did , but  it  doesn't  help  then  i  change nodePrint    by  def newXml=  groovy.xml.XmlUtil.serialize( xml ) and   it  worked   perfectly
 
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