如何修复1字节UTF-8序列的无效字节1

我正在尝试使用Java方法从数据库中获取以下xml,但出现错误

用于解析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中有一些特殊字符。如何解决这个问题?

回答:

如何解决这个问题?

使用正确的字符编码读取数据。错误消息表示您正在尝试以UTF-8格式读取数据(故意或因为这是未指定的XML文件的默认编码<?xml

version="1.0"

encoding="somethingelse"?>),但实际上它采用的是其他编码,例如ISO-8859-1或Windows-1252。

为了能够为您提供建议,我必须查看您当前用于读取XML的代码。

以上是 如何修复1字节UTF-8序列的无效字节1 的全部内容, 来源链接: utcz.com/qa/402116.html

回到顶部