如何修复1字节UTF-8序列的无效字节1 [英] How to fix Invalid byte 1 of 1-byte UTF-8 sequence

查看:132
本文介绍了如何修复1字节UTF-8序列的无效字节1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用java方法从db获取以下xml,但是我收到错误

I am trying to fetch the below xml from db using a java method but I am getting an error

用于解析xml的代码

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();

InputSource is = new InputSource(new ByteArrayInputStream(cond.getBytes()));

Document doc = db.parse(is);

Element elem = doc.getDocumentElement();

// here we expect a series of <data><name>N</name><value>V</value></data>
NodeList nodes = elem.getElementsByTagName("data");

TableID jobId = new TableID(_processInstanceId);
Job myJob = Job.queryByID(_clientContext, jobId, true);

if (nodes.getLength() == 0) {
    log(Level.DEBUG, "No data found on condition XML");

}

for (int i = 0; i < nodes.getLength(); i++) {
    // loop through the <data> in the XML

    Element dataTags = (Element) nodes.item(i);
    String name = getChildTagValue(dataTags, "name");
    String value = getChildTagValue(dataTags, "value");

    log(Level.INFO, "UserData/Value=" + name + "/" + value);

    myJob.setBulkUserData(name, value);
}

myJob.save();

数据

<ContactDetails>307896043</ContactDetails>
<ContactName>307896043</ContactName>
<Preferred_Completion_Date>
</Preferred_Completion_Date>
<service_address>A-End Address: 1ST HELIERST HELIERJT2 3XP832THE CABLES 1 POONHA LANEST HELIER JE JT2 3XP</service_address>
<ServiceOrderId>315473043</ServiceOrderId>
<ServiceOrderTypeId>50</ServiceOrderTypeId>
<CustDesiredDate>2013-03-20T18:12:04</CustDesiredDate>
<OrderId>307896043</OrderId>
<CreateWho>csmuser</CreateWho>
<AccountInternalId>20100333</AccountInternalId>
<ServiceInternalId>20766093</ServiceInternalId>
<ServiceInternalIdResets>0</ServiceInternalIdResets>
<Primary_Offer_Name  action='del'>MyMobile Blue &#163;44.99 [12 month term]</Primary_Offer_Name>
<Disc_Reason  action='del'>8</Disc_Reason>
<Sup_Offer  action='del'>80000257</Sup_Offer>
<Service_Type  action='del'>A-01-00</Service_Type>
<Priority  action='del'>4</Priority>
<Account_Number  action='del'>0</Account_Number>
<Offer  action='del'>80000257</Offer>
<msisdn  action='del'>447797142520</msisdn>
<imsi  action='del'>234503184</imsi>
<sim  action='del'>5535</sim>
<ocb9_ARM  action='del'>false</ocb9_ARM>
<port_in_required  action='del'>
</port_in_required>
<ocb9_mob  action='del'>none</ocb9_mob>
<ocb9_mob_BB  action='del'>
</ocb9_mob_BB>
<ocb9_LandLine  action='del'>
</ocb9_LandLine>
<ocb9_LandLine_BB  action='del'>
</ocb9_LandLine_BB>
<Contact_2>
</Contact_2>
<Acc_middle_name>
</Acc_middle_name>
<MarketCode>7</MarketCode>
<Acc_last_name>Port_OUT</Acc_last_name>
<Contact_1>
</Contact_1>
<Acc_first_name>.</Acc_first_name>
<EmaiId>
</EmaiId>

错误

 org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

我读了一些线程,因为xml中有一些特殊字符。
如何解决这个问题?

I read in some threads it's because of some special characters in the xml. How to fix this issue ?

推荐答案


如何解决这个问题?

How to fix this issue ?

使用正确的字符编码读取数据。错误消息表示您尝试将数据读取为UTF-8(故意或因为这是未指定<?xml version =1.0编码的XML文件的默认编码=somethingelse?> )但实际上它采用的是不同的编码,例如ISO-8859-1或Windows-1252。

Read the data using the correct character encoding. The error message means that you are trying to read the data as UTF-8 (either deliberately or because that is the default encoding for an XML file that does not specify <?xml version="1.0" encoding="somethingelse"?>) but it is actually in a different encoding such as ISO-8859-1 or Windows-1252.

为了能够就如何执行此操作提供建议,我必须查看您当前用于读取XML的代码。

To be able to advise on how you should do this I'd have to see the code you're currently using to read the XML.

这篇关于如何修复1字节UTF-8序列的无效字节1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆