SAXParser解析数据的问题
<message priority="info">PARAMETRI:</message>
<message priority="info">vrednost: 2.0</message>
<message priority="info">rank: 0.75</message>
−
<message priority="info">
objekt: irc.kis.model.pomozniRazredi.CasovniInterval.CasovniInterval(Date, Date)
</message>
<message priority="info">iid_tipa: 3</message>
<message priority="info">iid_metrike: 14</message>
<message priority="info">iid_izracuna: 140</message>
<message priority="info">done in 205776 ms</message>
<message priority="info">---------</message>
<message priority="info">Indeksi kakovosti</message>
<message priority="info">QI01: 3.9249</message>
<message priority="info">QI02: 4.0335</message>
<message priority="info">QI03: 4.0966</message>
<message priority="info">QI04: 4.3823</message>
<message priority="info">---------</message>
<message priority="info">QI05: 3.9401</message>
<message priority="info">QI06: 4.2479</message>
<message priority="info">QI07: 4.4984</message>
<message priority="info">QI08: 4.3534</message>
<message priority="info">QI09: 3.8455</message>
<message priority="info">QI10: 4.0195</message>
<message priority="info">QI11: 4.6222</message>
这是我的 xml 日志。我可以用 java SAXParser 得到
Indeksi kakovosti
QI01: 3.9249
QI02: 4.0335
QI03: 4.0966
QI04: 4.3823
----
如果是的话怎么办?
<message priority="info">PARAMETRI:</message>
<message priority="info">vrednost: 2.0</message>
<message priority="info">rank: 0.75</message>
−
<message priority="info">
objekt: irc.kis.model.pomozniRazredi.CasovniInterval.CasovniInterval(Date, Date)
</message>
<message priority="info">iid_tipa: 3</message>
<message priority="info">iid_metrike: 14</message>
<message priority="info">iid_izracuna: 140</message>
<message priority="info">done in 205776 ms</message>
<message priority="info">---------</message>
<message priority="info">Indeksi kakovosti</message>
<message priority="info">QI01: 3.9249</message>
<message priority="info">QI02: 4.0335</message>
<message priority="info">QI03: 4.0966</message>
<message priority="info">QI04: 4.3823</message>
<message priority="info">---------</message>
<message priority="info">QI05: 3.9401</message>
<message priority="info">QI06: 4.2479</message>
<message priority="info">QI07: 4.4984</message>
<message priority="info">QI08: 4.3534</message>
<message priority="info">QI09: 3.8455</message>
<message priority="info">QI10: 4.0195</message>
<message priority="info">QI11: 4.6222</message>
this is my xml log. Can i with java SAXParser get out just
Indeksi kakovosti
QI01: 3.9249
QI02: 4.0335
QI03: 4.0966
QI04: 4.3823
anything between ----
If yes how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您可以这样做(假设您的 xml 格式正确)。您必须创建一个 ContentHandler,并使用计数器实例变量来告诉您到目前为止已找到多少个
---------
分隔符。不要使用characters()来执行此操作,因为characters()可以被多次调用。相反,使用字符()缓冲读取的文本,使用endElement()读取最终文本并测试和递增计数器。
所以 ContentHandler 看起来像:
Yes, you can do that (assuming your xml is well-formed). You would have to create a ContentHandler, with a counter instance variable to tell how many of the
---------
delimiters you've found so far.Do not use characters() to do this, because characters() can be called multiple times. Instead buffer the text read using characters(), use endElement() to read the final text and test and increment the counters.
So the ContentHandler would look like:
一定是这样的。
但是您的文档必须格式良好(具有根元素并且没有未知字符,如第四行)。
It must be something like this.
But your document has to be well formed (with root element and without unknown characters like in fourth row).