2013-04-09 98 views
-5
HTML 1 I m getting this in string -> 

    S=   
      "<html> <head> <link rel='stylesheet' type='text/css' 
      href='http://www.taxmann.com/css/taxmannstyle.css' /> 
       </head> <body ><html> 
       <body style='background-color:Black;font-size:30px;color:#fff;'> 
     <div id=\"digest\">\r\n 
        <p class=\"threedigest\">ST : Extended period of limitation 
       cannot be invoked for not paying tax if there was divergence 
     of opinion during relevant 
       period and 
       some judgments were in favour of assessee, 
       as there could be no suppression/wilful mis-statement 
     by assessee</p>\r\n 
       </div></body></html></body></html>" 

注:我得到這個HTML這是正確的如何使用替代或C#或Java刪除commoand轉換HTML

BUT String HTML 2 -> 

      "<html> 
        <head> <link rel='stylesheet 
        ' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' /> 
        </head> <body ><html><body style='background-color:Black;font-size:30px;color:#fff;'> 
        <html>\r\n<head> 
        <link href='http://www.taxmann.com/TaxmannWhatsnewService/Styles/style.css' rel='stylesheet' type='text/css' /> 
        \r\n<title>Rs.560-crore tax evasion detected</title>\r\n<style type=\"text/css\"> 
      \r\nbody 
        {font-family:Arial, Helvetica, sans-serif; font-size:12px; 
       line-height:18px;text-align:justify;} 
        \r\n.w100{width:100%;}\r\n.fl-l{float:left;}\r\n.ffla{font-family:Arial, 
       Helvetica, sans-serif;} 
        \r\n.fs18{font-size:18px;}\r\n.mart10{margin-top:10px;}\r\n.fcred{color:#c81616;} 
       \r\n.tc{text-align:center;}\r\n.tu{text-transform:uppercase;}\r\n.lh18{line-height:18px;}\r\n</style>\r\n</head>\r\n<body>\r\n 
       <div class=\"w100 fl-l\">\r\n<div class=\"w100 fl-l ffla fs18 mart10 fcred ttunderline tc tu\"> 
        Rs.560-crore tax 
vasion detected</div>\r\n\r\n<div class=\"w100 fl-l lh18 mart10\"> 
       The Central Excise Intelligence, 
Chennai Zone, has detected 164 cases involving excise 
       and service tax evasion of Rs.560 crore in 2012- 13. 
    A total of 166 show cause notices 
       have been issued involving Rs.500 crore for 
    various central excise and service 
       tax cases during the year. 
– www.business-standard.com</div>\r\n\r\n 
      </div>\r\n</body>\r\n 
        </html>\r\n</body> 
    </html></body> 
    </html>" 

我想轉換爲HTML1格式我試過很多HTML 2格式相同但無法做到。我試圖刪除一些HTML內容,但它沒有工作,我不知道如何轉換Html2相同,因爲它Html1即使我也試圖刪除這個使用Java但無法做到請幫助我!使用任何編程語言中的replace或remove命令。

回答

0

試試這個工作,即刪除代碼中第一行中的兩個不需要的html標籤,即服務器的響應有兩個html標籤,因爲您沒有得到正確的響應。嘗試刪除所有不需要的標記並對齊html代碼

public class TestScriptClass { 
public static void main(String[] args) { 

    String inputValue=" "; 
     inputValue =inputValue+"<html><head> <link rel='stylesheet' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' />"+ 
        "</head> <body ><html><body style='background-color:Black;font-size:30px;color:#fff;'>"+ 
        "<html>\r\n<head> <link href='http://www.taxmann.com/TaxmannWhatsnewService/Styles/style.css' rel='stylesheet' type='text/css' />"+ 
        "\r\n<title>Rs.560-crore tax evasion detected</title>\r\n<style type=\"text/css\">"+ 
        " \r\nbody{font-family:Arial, Helvetica, sans-serif; font-size:12px; "+ 
        " line-height:18px;text-align:justify;} \r\n.w100{width:100%;}\r\n.fl-l{float:left;}\r\n.ffla{font-family:Arial, "+ 
        "Helvetica, sans-serif;} \r\n.fs18{font-size:18px;}\r\n.mart10{margin-top:10px;}\r\n.fcred{color:#c81616;}"+ 
        " \r\n.tc{text-align:center;}\r\n.tu{text-transform:uppercase;}\r\n.lh18{line-height:18px;}\r\n</style>\r\n</head>\r\n<body>\r\n"+ 
        " <div class=\"w100 fl-l\">\r\n<div class=\"w100 fl-l ffla fs18 mart10 fcred ttunderline tc tu\">"+ 
        " Rs.560-crore tax "+ 
        "vasion detected</div>\r\n\r\n<div class=\"w100 fl-l lh18 mart10\">"+ 
        " The Central Excise Intelligence, "+ 
        "Chennai Zone, has detected 164 cases involving excise"+ 
        " and service tax evasion of Rs.560 crore in 2012- 13."+ 
        " A total of 166 show cause notices"+ 
        " have been issued involving Rs.500 crore for "+ 
        " various central excise and service "+ 
        " tax cases during the year."+ 
        "– www.business-standard.com</div>\r\n\r\n"+ 
        " </div>\r\n</body>\r\n"+ 
        " </html>\r\n</body>"+ 
        " </html></body>"+ 
        " </html>"; 

     String resultValue= inputValue.replace("<html><head> <link rel='stylesheet' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' /></head> <body ><html>", " <html><head> <link rel='stylesheet' type='text/css' href='http://www.taxmann.com/css/taxmannstyle.css' />"); 

     System.out.println(resultValue);  
} 
}