如何解析不完整的xml文件 [英] How to parse a incomplete xml file

查看:235
本文介绍了如何解析不完整的xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个程序来逐步获取xml文件。即文件不断以xml feed的形式更新。因此,第一个块将不是一个格式良好的xml文档。但是我需要定期解析feed并显示解析结果。


如何实现这一目标。


例如...


xml字段可以关注


第一个块如下:我们可以看到它没有很好地形成

I have to write a program where we get the xml file incrementally. i.e the file is constantly updated in the form of xml feed. Thus the first chunk will not be a well formed xml document. However i need to parse the feeds regularly and display the parsed result.

How can this be achieved.?

Eg...

xml field can be following

First chunk is as follows: We can see it is not well formed

展开 | 选择 | Wrap | 行号

推荐答案

任何合理的xml解析器都会抛出错误如果文件格式不正确。但是,有一些方法可以扩展带有附加数据的xml文件(我说的是DOM)而不使用无效的xml,尽管这取决于块的结构。


我建议更改更新过程,因为xml处理在格式良好的xml上会更容易。


如果绝对没有办法,你可以尝试解析文件标签(就像PHP xml_parse()函数一样。


问候
any reasonable xml parser will throw an error if the document is not well-formed. however, there are ways to extend an xml file with additional data (I''m speaking of DOM) without ever using invalid xml, although that depends on the structure of the chunks.

I recommend changing the update process, since xml processing will be much easier on well formed xml.

if there is absolutely no other way, you can try to parse the file tag-wise (like the PHP xml_parse() function).

regards


@Dormilich


您好Dormilich,


问题是从服务器检索xml提要并在用户屏幕上不断更新。所以我必须解析给定的feed,然后在获得xml feed时更新用户界面。


你能提供样本代码来做同样的事吗?
@Dormilich

Hi Dormilich,

The problem is the xml feed is retrieved from the server and is constantly updated on the user screen. So i have to parse the given feed and then update the user screen as and when the xml feed is got.

Can you provide me with the sample code to do the same?


如果你从服务器获得一个源,它的形式大多是格式良好的。以何种方式处理的Feed被显示在屏幕上?
if you get a feed from a server, it is mostly well-formed. in which way is the feed processed to show up on screen?


这篇关于如何解析不完整的xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆