I'm facing an issue with removing whitespaces within the value fields in the xml data.
eg:
Input
<?xml version="1.0"?>
<ns:myOrder xmlns:ns="http://w3schools.com/BusinessDocument" xmlns:ct="http://something.com/CommonTypes">
  <MessageHeader>
     <ct:ID>i7                           </ct:ID>
     <ct:ID>i7                           </ct:ID>
     <ct:ID>i7                           </ct:ID>
     <ct:ID>i7                           </ct:ID>
     <ct:Name> Company Name           </ct:Name>
 </MessageHeader>
</ns:myOrder>
Expected output:
<?xml version="1.0"?>
  <ns:myOrder xmlns:ns="http://w3schools.com/BusinessDocument" xmlns:ct="http://something.com/CommonTypes">
    <MessageHeader>
       <ct:ID>i7</ct:ID>
       <ct:ID>i7</ct:ID>
       <ct:ID>i7</ct:ID>
       <ct:ID>i7</ct:ID>
       <ct:Name>Company Name</ct:Name>
    </MessageHeader>
  </ns:myOrder>
I tried with the below code
public static String getTrimmedXML(String rawXMLFilename) throws Exception
     {
          BufferedReader in = new BufferedReader(new FileReader(rawXMLFilename));
     String str;
     String trimmedXML = null;     
     while ((str = in.readLine()) != null) 
     {
          String str1 = str;
          if (str1.length()>0) 
          {
               str1 = str1.trim();
               if(str1.charAt(str1.length()-1) == '>')
               {
                    trimmedXML = trimmedXML + str.trim();
               }
               else
               {
                    trimmedXML = trimmedXML + str;
               }
          }
     }     
     in.close();
     return trimmedXML.substring(4);
     }
I'm unable to remove those spaces. Please let me know where i'm going wrong
Regards, Monish
 
     
     
     
     
     
     
    