fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String content =" <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
  13. "<!DOCTYPE DocName PUBLIC \"-//msg//msg1 Project_Name 1.1//EN\" \"My_Project_Name_V1_1.dtd\">\n"+
  14. "<My_Project_Name dtdVersion=\"V1_1\" fileName=\"Guidance_Document_SQL\" softwareName=\"prototype\" softwareVersion=\"0.1\" productionDate=\"2012-01-02\">\n"+
  15. " <ApplicantFileReference>ABCD#1234</ApplicantFileReference>\n"+
  16. " <ApplicantName languageCode=\"EF\">Michael Smith</ApplicantName>\n"+
  17. " <ApplicantNameLatin>Michael Smith </ApplicantNameLatin>\n"+
  18. " <ProductTitle languageCode=\"EF\">Some Example </InventionTitle>\n"+
  19. " <TotalQuantity>88</TotalQuantity>\n"+
  20. " <Example_Data exampleIDNumber=\"1\">\n"+
  21. " <Exm_Seq>\n"+
  22. " <Exm_Seq_length>7</Exm_Seq_length>\n"+
  23. " <Exm_Seq_type>MM</Exm_Seq_type>\n"+
  24. " <Exm_Seq_div>PAT</Exm_Seq_div>\n"+
  25. " <Exm_Seq>\n"+
  26. " </Example_Data>";
  27.  
  28. String newLine = "\n";
  29.  
  30. String bodyStart ="<Example_Data";
  31.  
  32. int indx = content.indexOf(bodyStart);
  33. String head = content.substring(0, indx - 1);
  34.  
  35. int lastNewline = head.lastIndexOf(newLine);
  36. String body;
  37. if(lastNewline != -1 && content.charAt(indx - 1) != '>') {
  38. body = content.substring(lastNewline + 1);
  39. }
  40. else {
  41. body = content.substring(indx);
  42. }
  43.  
  44.  
  45. System.out.println(body);
  46. }
  47. }
Success #stdin #stdout 0.09s 27828KB
stdin
Standard input is empty
stdout
    <Example_Data exampleIDNumber="1">
        <Exm_Seq>
            <Exm_Seq_length>7</Exm_Seq_length>
            <Exm_Seq_type>MM</Exm_Seq_type>
            <Exm_Seq_div>PAT</Exm_Seq_div>
        <Exm_Seq>
    </Example_Data>