gpt4 book ai didi

java - xmlbeans.xml 异常。非法 XML 字符 0x0

转载 作者:行者123 更新时间:2023-11-29 09:31:11 24 4
gpt4 key购买 nike

我通过 System.Text.UTF8Encoding() 将字符串转换为字节,在 C# 中创建了一个 xml 文档。然后我将它发送到我的 java 程序,以便 xmlbeans 通过 TCP 连接进行解析。无论我尝试什么,我都会收到此错误:org.apache.xmlbeans.XmlException:错误:非法 XML 字符:0x0org.apache.xmlbeans.impl.piccolo.io.IllegalCharException:非法 XML 字符:0x0

我试图在 C# 端清理字符串,但它没有找到 0x0 的任何实例。我已经遍历并输出了我在 Java 端收到的 byte[] 中的每个字节,绝对没有任何内容具有 0x0。

这是我的java端代码:

    public void parseBytes(byte[] bytes, int length, String source)
{
System.out.println("***************BmsDrawingGatewayParser - ParseBytes " + length);

String foundData = null;
try
{
foundData = new String(bytes, 0, length, "UTF-8");
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
}
switch (readState)
{
case STATE_NEW_MSG:
// if contains the
if (foundData.contains(startMessageTag))
{
if (foundData.contains(endMessageTag))
{
byteStream.write(bytes, 0, length);
parseXml(byteStream.toByteArray());
if (byteStream.size() > 0)
{
byteStream.reset();
}
}
else
{
readState = DrawingDeviceParserState.STATE_READING_MSG;
}
}
else
{
System.out.println("Couldn't find start tag");
System.out.println(foundData);
}
break;

case STATE_READING_MSG:
byteStream.write(bytes, byteStream.size(), length);
if (foundData.contains(endMessageTag))
{
System.out.println("Now going to parse");
//parseXml(xmlString.toString());
parseXml(byteStream.toByteArray());
byteStream.reset();
readState = DrawingDeviceParserState.STATE_NEW_MSG;
}
else
{
System.out.println("Couldn't find end tag");
System.out.println(foundData);
}
break;
}
}

private void parseXml(byte[] xmlData)
{
System.out.println(xmlData);

//EventDocument.Factory.parse
ByteArrayInputStream sid = new ByteArrayInputStream(xmlData);
try
{
EventDocument eventDoc = EventDocument.Factory.parse(sid);
if (eventDoc.validate())
{
System.out.println("Document is valid");
}
else
{
System.out.println("Document is INVALID");
}
EventDocument.Event myEvent = eventDoc.getEvent();
EventDocument.Event.Detail[] myDetailArray = myEvent.getDetailArray();

//myDetailArray[0].

//BmsDrawingDocument drawingDoc = myEvent.getDetail();
System.out.println("MY UID: " + myEvent.getUid());
}
catch(Exception xmlException)
{
System.out.println(xmlException.toString());
xmlException.printStackTrace();
}
}

有谁知道我可能做错了什么?我可以提供更多信息吗?

最佳答案

这件事发生在我身上,发现是损坏的 lib 文件,所以用未损坏的或旧的副本替换 libs。它解决了我的问题。

关于java - xmlbeans.xml 异常。非法 XML 字符 0x0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7614118/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com