0

i am reading one xml file to another file it is fine but while reading i am checking condition for updation of one statement but it is not updating, please suggest me on this

public class PutMesageDebugger {


    public static void main(String[] args) throws IOException {

    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("C:/PutMessageDebugger/Sub_Workflow_HSS.xml"), "UTF-8"));
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:/PutMessageDebugger/tempSub_Workflow_HSS.xml"), "UTF-8"));

     String line = null;

     while ((line = reader.readLine()) != null){                   
     //System.out.println("line"+ line);

      //System.out.println(line.contains("<Process-Node"));
        /*System.out.println(line.contains("<Class-Name>com.hp.ov.activator.mwfm.component.builtin.PutMessage</Class-Name>"));
           System.out.println(!line.contains("inactive=true"));
                         */
         if ( line.contains("<Class-Name==com.hp.ov.activator.mwfm.component.builtin.PutMessage")){
             line = line.replaceAll("<Process-Node","<Process-Node inactive=\"true\" ");

                  }

             writer.write(line + "\n");



                  }

              reader.close();
              writer.close();

           }
Shriram
  • 4,343
  • 8
  • 37
  • 64
  • I would strongly avoid reading XML line by line to start with. Why not read it *as an XML document*? At the moment your code is *very* sensitive to the exact format, which appears to contain a rather bizarre element name. If it's actually valid XML, treat it as such. You may be able to just use XSLT to perform the transformation you want, in fact. – Jon Skeet Jan 13 '16 at 06:48
  • Hi Jon, xml transaformation is fine but in that if condition if(line.contains(" – shekar vanamala Jan 13 '16 at 06:56

1 Answers1

0

It is not a good idea to parse XML like that. You should use a XML library, which takes care of white-space handling and many other things for you. Take a look at the javax.xml package.

If all you want to do is to add the inactive="true" attribute to the ProcessNode element, you could go for XSLT. There are many resources on how to do that, e.g. add attribute example

Community
  • 1
  • 1
stevops
  • 429
  • 3
  • 9