开发者

Splitting XML string with multiple XML documents using Java split() method

I am reading XML documents from a stream into a string. However, there is the possibility of multiple XML documents (identically structured) within the same string. I read several questions on stackoverflow and other sites which provided examples of splitting using XPath and some other methods. In my case will it be fine for me to simply use Java's String.spit() method?

All I require is for a string with two or more identically struc开发者_开发技巧tured XML documents be split into separate strings. I'm asking because I have not seen anyone else made mention of this, so in the event that I am missing the obvious reason for this please point it out. Thank you.

Each document is structured as follows:

<?xml version = "1.0" encoding = "UTF-8"?>
<telemetry>
........
</telemetry>


If you know that each document starts with <?xml version = "1.0" encoding = "UTF-8"?>, you can use that as a delimiter (since it cannot legally be part of the document). You can also consume the delimiter if that makes splitting the string easier; absence of the xml declarattion will not affect the parsing, since it is the default.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜