2012-03-25 126 views
0

我想解析一個格式類似於Xml(但不是XML格式)的文檔,它適用於除了當我到達一個HTML代碼如& ldquo時。然後我得到一個錯誤,一切都崩潰了。我怎樣才能解決這個問題XmlPullParser無法解決:「

編輯下載錯誤和它發生的行: 03-25 17:56:26.540:W/System.err(21265):org.apache.harmony.xml.ExpatParser $ ParseException的:在第68行,列354:未定義的實體

<F_S_INGREDIENTS>Pale ale malt (well-modified and suitable for single-temperature infusion mashing); American hops; American yeast that can give a clean or slightly fruity profile. Generally all-malt, but mashed at lower temperatures for high attenuation. Water character varies from soft to moderately sulfate. Versions with a noticeable Rye character (&ldquo;RyePA&rdquo;) should be entered in the Specialty category.</F_S_INGREDIENTS> 

伊夫範圍縮小到「 RyePA 」

回答

1

&ldquo是一個有效的HTML實體,但不是有效的XML實體。你不能用股票XML解析器解析它。

defineEntityReplacement()方法看起來很有前景。如果你不能爲你工作,你可以簡單地將字符串讀入內存(如果它不是太錯誤),然後把它交給解析器,自己替換文本,

String s = xml.replaceAll("&ldpos;", "\"").replaceAll("&rdpos;", "\""); 
+0

對不起忘了發佈它在這裏它是:03-25 17:37:37.340:W/System.err(20355):org.apache.harmony.xml.ExpatParser $ ParseException:在第68行,列354:未定義實體 – DRing 2012-03-25 22:42:22

+0

這是不夠的信息。它沒有說明哪個實體是未定義的,並且您沒有在源代碼.xml文件中發佈第68行的內容。 – 2012-03-25 23:09:05

+0

對不起,有點累,用文件中的行更新一下,錯誤 – DRing 2012-03-25 23:21:04