繁体   English   中英

在文档的元素内容中发现使用ow3c.dom.Document对象(Unicode:0x1a)解析文档时发生解析错误

[英]parsing error while parsing document using ow3c.dom.Document object, (Unicode: 0x1a) was found in the element content of the document

我收到错误消息: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 14515; An invalid XML character (Unicode: 0x1a) was found in the element content of the document org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 14515; An invalid XML character (Unicode: 0x1a) was found in the element content of the document org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 14515; An invalid XML character (Unicode: 0x1a) was found in the element content of the document

我收到错误的xml文件内容:

 <Product>
          <Description>672577000 3M 4540 DISPOSABLE COVERALL → XL</Description>
 </Product>

使用org.w3c.dom.Document对象解析文档时出现此错误,由于输入文件中的→导致发生错误。 那么如何解决此问题?

xml文件中不允许所有字符。 这是一个链接,供您查找允许或不鼓励使用哪个,并且不允许进行重置:

http://en.wikipedia.org/wiki/Valid_characters_in_XML

您的(→)不允许。

I resolved this by using below code
String removedUnicodeChar  = "DISPOSABLE COVERALL → XXL</Description></Order> ↔ ↕ ↑ ↓ → ABC";
Pattern pattern = Pattern.compile("[\\p{Cntrl}|\\uFFFD]");
Matcher m = pattern.matcher(removedUnicodeChar);
if(m.find()){
    System.out.println("Control Characters found");
    removedUnicodeChar = m.replaceAll("");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM