有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在解析流式XML数据时遇到异常

我正在尝试使用Spark streaming解析流数据。我从卡夫卡接收输入数据,然后像JavaPairInputStream->;rdd。我的RDD是这样的:

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

我正在逐行获取数据。接下来,我将尝试使用Stax解析器进行解析。这是我的密码:

XMLStreamReader reader;
XMLInputFactory factory = XMLInputFactory.newInstance(); 
InputStream in = IOUtils.toInputStream(items._2, "UTF-8");
reader = factory.createXMLStreamReader(in);

当我试着这样做的时候,我

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,7]
Message: XML document structures must start and end within the same entity.

当我试着这样做的时候

reader = factory.createXMLStreamReader(new FileReader(items._2));

我越来越

16/12/27 15:17:26 ERROR executor.Executor: Exception in task 0.0 in stage 1.0 (TID 1)
java.io.FileNotFoundException: <note> (No such file or directory)

共 (0) 个答案