如何在java中用xml标记替换html标记

时间:2010-11-11 14:48:29

标签: java html xml regex parsing

我从网络服务中获取价值,例如很多标签范围样式,p,类样式c& &安培; QUOT。我想转换为xml标记并解析该值。谁能告诉我如何将html标签转换为xml标签? 举个例子

我的网络服务价值是:

11-11 19:35:36.922: INFO/System.out(6956): Article detail response<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getDataResponse xmlns="http://tempuri.org/QuestIPhoneWebService/QuestIPhoneWebService"><getDataResult>&lt;ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"&gt;&lt;ARTICLE ARTICLE_ID="23221" HIDE_HEADER="0" MIGRATED="0" CITNART_DOC_REGION_INFO="" ISCSUSER="1" ARTICLE_TYPE_ID="31" ARTICLE_TYPE="Mobile- News and Commentary - Europe" CITN_ISSUE_NUMBER="" CITN_ARTICLE_TYPE_ID="" CITN_ARTICLE_TYPE="" SHOW_AUTH="1" LOGO_TYPE="QUEST" TITLE="Elementis - europe" DATE="2010-11-04T11:58:21.387" BODY="&amp;lt;span style=&amp;quot;WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium 'Times New Roman'; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: none; -webkit-text-stroke-width: 0px&amp;quot; class=&amp;quot;Apple-style-span&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;Apple-style-span&amp;quot;&amp;gt;
11-11 19:35:36.932: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;At the end of 2008, the FTSE350 chemical sector consisted of just two names &amp;amp;#8211; Johnston Matthey and Croda. Since then we have had the admission of Victrex and, as of last week, Elementis and Yule Catto. Having met management, we believe that Elementis has all the ingredients for value creation that Croda has so successfully exhibited.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
11-11 19:35:36.961: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;Being promoted into the FTSE250 opens Elementis up to a whole new investment audience. It has not just got there through a cyclical bounce back either. The company has gone through a very sensible rationalisation programme, exited a low-returning business (UK Chromium), is running much more efficient levels of working capital, and crucially, is more exposed to growth markets. To give an idea of management&amp;amp;#8217;s resolve, instead of selling the UK Chromium business they decided to effectively bulldoze the site. This will prevent a competitor from interfering in Elementis&amp;amp;#8217; position in US Chromium.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
11-11 19:35:36.971: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;During the credit crunch Elementis picked up an Asian-focused speciality chemicals business called Deuchem for &amp;amp;#163;38m (&amp;amp;#163;45m sales). Deuchem has 12 offices in&amp;lt;?xml:namespace prefix = st1 /&amp;gt;&amp;lt;st1:country-region&amp;gt;&amp;lt;st1:place&amp;gt;China&amp;lt;/st1:place&amp;gt;&amp;lt;/st1:country-region&amp;gt;&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;and is benefiting as the Chinese customer moves up the quality/performance scale. Previously, Chinese demand was not for sophisticated products &amp;amp;#8211; this is changing as we type. Coatings are the main market for speciality products, with Oilfield Chemicals the next biggest category. The cost of Elementis&amp;amp;#8217; products per end unit remains small, typically &amp;amp;lt;5%. Yet the relationship with the customer (its largest is Akzo Nobel) is generally one that has been forged over many years (even decades) and required them to work closely together. In short, it is not particularly competitive, but does require consistent delivery and performance from Elementis. We have a very conservative top-line growth forecast of 3% for specialty chemicals, yet would not be surprised if it was nearer 5%. Margin progression here is key and we expect a mid-to-high teens margin up from 9%.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
11-11 19:35:36.983: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;Another growth area is shale gas. Elementis makes the lubricant for the drill bit. Typically, drilling was vertical. But, now drill bits can be turned 90 degrees accessing much more of the shale seam. This requires much more lubricant &amp;amp;#8211; hence H1 2010 volumes were double the year before. There is only one competitor in this area. Elsewhere in the US Elementis has its US Chromium business. This is steady, has high&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;st1:country-region&amp;gt;US&amp;lt;/st1:country-region&amp;gt;&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;market shares and has a superior transport advantage to competitors exporting to the&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;st1:country-region&amp;gt;&amp;lt;st1:place&amp;gt;US&amp;lt;/st1:place&amp;gt;&amp;lt;/st1:country-region&amp;gt;. This is a solid business growing at 3% with a 15% operating margin.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
11-11 19:35:36.983: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;Since the credit crunch the CFO has tightened up inventory management and creditor days. This has helped to transfer c.&amp;amp;#163;25m of value to shareholders, a vital step in maximizing returns for shareholders. On a separate note management think there is a chance that an EU fine worth &amp;amp;#163;21m that Elementis has paid could be reversed.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
11-11 19:35:36.992: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;We&amp;amp;#8217;ve updated the Modeller approach we used in last month&amp;amp;#8217;s CITN note &amp;amp;#8220;&amp;lt;a href=&amp;quot;http://www.csquest.com/QUEST?uid=MAIL&amp;amp;amp;Tp=Cn&amp;amp;amp;PCF=CNAR&amp;amp;amp;ID=23243&amp;quot; target=&amp;quot;_blank&amp;quot;&amp;gt;It&amp;amp;#8217;s Elementary&amp;lt;/a&amp;gt;&amp;amp;#8221;. Instead of using a&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;a href=&amp;quot;http://www.csquest.com/QUEST?clpg=ART&amp;amp;amp;id=13586&amp;amp;amp;clid=&amp;amp;amp;pg=MDL&amp;amp;amp;spl=&amp;amp;amp;cid=0241854&amp;quot; target=&amp;quot;_blank&amp;quot;&amp;gt;central valuation (100p)&amp;lt;/a&amp;gt;&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;&amp;amp;#8211; half way between the&amp;lt;a href=&amp;quot;http://www.csquest.com/QUEST?clpg=ART&amp;amp;amp;id=13629&amp;amp;amp;clid=&amp;amp;amp;pg=MDL&amp;amp;amp;spl=&amp;amp;amp;cid=0241854&amp;quot; target=&amp;quot;_blank&amp;quot;&amp;gt;bull (135p)&amp;lt;/a&amp;gt;&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;and bear (67p) scenarios &amp;amp;#8211; since seeing management, we&amp;amp;#8217;re now happier using a valuation halfway between the bull case and the central case. Given this renewed confidence, we think this 118p adjusted valuation is very credible indeed. With 24% upside to Friday&amp;amp;#8217;s close, Elementis is a buy.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
11-11 19:35:36.992: INFO/System.out(6956): &amp;lt;p&amp;gt;
11-11 19:35:37.002: INFO/System.out(6956): &amp;lt;table style=&amp;quot;WIDTH: 345.75pt; BORDER-COLLAPSE: collapse; MARGIN-LEFT: 4pt&amp;quot; class=&amp;quot;MsoTableGrid&amp;quot; border=&amp;quot;0&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;0&amp;quot; width=&amp;quot;461&amp;quot;&amp;gt;
11-11 19:35:37.012: INFO/System.out(6956): &amp;lt;tbody&amp;gt;
11-11 19:35:37.023: INFO/System.out(6956): &amp;lt;tr&amp;gt;
11-11 19:35:37.023: INFO/System.out(6956): &amp;lt;td style=&amp;quot;PADDING-BOTTOM: 0cm; PADDING-LEFT: 5.4pt; WIDTH: 345.75pt; PADDING-RIGHT: 5.4pt; PADDING-TOP: 0cm&amp;quot; valign=&amp;quot;top&amp;quot; width=&amp;quot;461&amp;quot;&amp;gt;
11-11 19:35:37.033: INFO/System.out(6956): &amp;lt;p style=&amp;quot;LINE-HEIGHT: 11pt; MARGIN: 0.75pt 0cm 0.75pt -3.95pt&amp;quot; class=&amp;quot;MsoNormal&amp;quot;&amp;gt;&amp;lt;b&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;Sales Team&amp;lt;/span&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;span lang=&amp;quot;EN-US&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;Apple-converted-space&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/span&amp;gt;&amp;lt;a href=&amp;quot;mailto:salesteam@collinsstewart.com&amp;quot; target=&amp;quot;_blank&amp;quot;&amp;gt;salesteam@collinsstewart.com&amp;lt;/a&amp;gt;, Tel: +44 (0) 20 7523 8493&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/tbody&amp;gt;&amp;lt;/table&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;" IS_PROTECTED="0" PDF_NAME="" REFERENCE_CITN_ARTICLE_ID="23221" ISNEWARTICLE="5" HYPERLINK="/PATH/23221.pdf"&gt;&lt;SUMMARY&gt;Elementis Europe Summary&lt;/SUMMARY&gt;&lt;AUTHORS/&gt;&lt;/ARTICLE&gt;&lt;ASSOCIATED_COMPANIES ARTICLE_ID="23221"/&gt;&lt;COMPANIES_WITH_AUTH context="COMPANIES"/&gt;&lt;/ROOT&gt;
11-11 19:35:37.033: INFO/System.out(6956): </getDataResult></getDataResponse></soap:Body></soap:Envelope>

2 个答案:

答案 0 :(得分:0)

他们会告诉你使用HTML解析类,这不是一个非常糟糕的建议。但是,如果问题空间足够有限(就像你在这里一样),可以使用正则表达式 。这是否有意义取决于几个方面,包括你自己对这两种方法的舒适程度。

我不能说那个正则表达式可能是什么,因为你没有显示精确你需要什么样的输出给定一些特定的输入。如果你这样做,我会编辑这个答案,告诉你如何。

答案 1 :(得分:0)

您也可以使用htmlcleaner。它可以将任何HTML代码转换为XML。

网站:http://htmlcleaner.sourceforge.net/
代码用法:http://htmlcleaner.sourceforge.net/javause.php