- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用以下两种方法来解析我的 Xml 数据:
private static XMLReader prepareSAX() throws ParserConfigurationException,
SAXException {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
return sp.getXMLReader();
}
public static void LectorSAX(XMLReader xr, String url) {
try {
InputSource is = new InputSource(url);
is.setEncoding("UTF-8");
xr.parse(is);
} catch (SAXException e) {
System.err.println("Error de sax LectorSAX.java: " + e);
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error de io LectorSAX.java: " + e);
e.printStackTrace();
}
}
现在我的 Xml 数据如下:
<Product>
<Product_ID>22434</Product_ID>
<Chinese_Name>三Q 逆齡速效霜</Chinese_Name>
<English_Name>Q10 QUICK GEL MOIST & WHITENING</English_Name>
<Image_Path>http://www.abc.com/prodImage/dtl/13011015,38,8.jpg</Image_Path>
<Original_Price>880</Original_Price>
<Discounted_Price>0</Discounted_Price>
<Product_Detail><![CDATA[<html><body>三Q 逆齡速效霜</br>Q10 QUICK GEL MOIST & WHITENING<br><br></body></html>]]></Product_Detail>
</Product>
我得到以下异常:
01-29 04:14:10.637: W/System.err(1665): Error de sax LectorSAX.java: org.apache.harmony.xml.ExpatParser$ParseException: At line 185, column 36: unknown encoding
01-29 04:14:10.758: W/System.err(1665): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
01-29 04:14:10.758: W/System.err(1665): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
01-29 04:14:10.758: W/System.err(1665): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
01-29 04:14:10.818: W/System.err(1665): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:294)
01-29 04:14:10.818: W/System.err(1665): at com.dhc.xmlparsing.XMLParser.LectorSAX(XMLParser.java:79)
我的第 185 行是 English_Name Tag。所以我哪里做错了,请帮助我。
最佳答案
终于找到了解决方案,这是 saxParser 编码“&”(特殊字符)的问题,所以我用 &
替换了“&
”。现在它运行良好,代码如下所示:
response = response.replaceAll("&", "&");
InputSource inputSource = new InputSource();
inputSource.setEncoding("UTF-8");
Log.i("TAG", "response" + response);
inputSource.setCharacterStream(new StringReader(response));
xr.parse(inputSource);
关于android - org.apache.harmony.xml.ExpatParser$ParseException(无效 token ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21422101/
我在云中有一个表“用户”,其中包含用户名、经度、纬度字段。我以用户身份登录。我想在欢迎 Activity 中检索特定 ID 的记录。我关注了 parse.com 文档,非常有帮助。我按照文档中提到的检
我有一个@Service带注释的服务类方法createShiftPlan(int numberOfEmployees, int startingMonth, int year)我在其中使用 Simpl
我有像“2015-07-13T10:44:58Z”这样的时间戳字符串,当我尝试将其转换为日期对象时,它总是会生成异常 由以下原因引起:java.text.ParseException:无法解析日期:“
您好,我正在尝试将字符串解析为日期,但它抛出异常 java.text.ParseException: Unparseable date: "1409239380000"(at offset 13)。这
执行以下代码时,我收到 ParseException: double toMilliseconds(double ds2) throws ParseException { long durin
我在将日期从 String 解析为 Date 对象时遇到 ParseException。日期字符串还包含时区。我正在使用这段代码: final SimpleDateFormat sdf = new S
我正在尝试转换此日期 2013-03-04T12:08:52.74+08:00 formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
我正在使用 jdbc:odbc 连接从 eclipse 连接到 Access 2010 数据库。我编写了一种方法来格式化日期值,然后将它们插入数据库中的表中。但是,当我尝试运行它时,堆栈跟踪打印出以下
我想解析字符串格式“9/7/2016 07:40 p.m.”到日期。但我遇到了解析异常。我尝试使用两种三种格式。但仍然遇到异常。 我想将此解析日期与当前日期进行比较。 SimpleDateF
我需要对代表日期的字符串列表进行排序。 我尝试了以下代码: try { SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd");
我有一个名为 DateCompareOld 的字符串,它的值为“Fri Aug 12 16:08:41 EDT 2011”。我想将其转换为日期对象。 SimpleDateFormat dateTyp
这个问题已经有答案了: Datetime parsing error (2 个回答) 已关闭 5 年前。 我正在处理日期字符串,我需要解析为 java“Date”对象。这是我到目前为止所得到的: tr
我编写了一段代码来解析日期字符串 - DateFormat cal = new SimpleDateFormat("yyyy-MM-dd hh:mm"); cal.setLenient
我有以下字符串:dateToParse = "Fri May 16 23:59:59 BRT 2014",我想使用 DateFormat 解析它: DateFormat dateFormat = ne
为什么我会收到此异常? 这是我的格式字符串: SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 这是我
解析日期格式时出现异常? java.text.ParseException:无法解析的日期:“10-10-2016” 在这一行: newSelection5 = DateFormat.getDateI
我需要将输入日期格式更改为我想要的格式。 String time = "Fri, 02 Nov 2012 11:58 pm CET"; SimpleDateFormat displayFormat =
我正在运行以下代码: DateFormat fullDate = new SimpleDateFormat("HHmmdd/MMMyy"); Date date = fullDate.parse("0
我正在尝试使用 SimpleDateFormat 解析以下日期:2015 年 9 月 3 日上午 10:00 (UTC-08:00)。 我最远的是: message = "10:00 AM UTC-0
我遇到了一个非常奇怪的问题,一小段代码在一台机器上运行,而不是在另一台机器上运行。这段代码: DateTimeFormatter formatter = DateTimeFormatter.o
我是一名优秀的程序员,十分优秀!