我有一個巨大的文本文件,我想寫一個程序,只能從文件中提取XML並保存。如何從純文本文件中提取嵌入的XML內容?
是否有一個直接的API或更好的解決方案,而不是分割/修剪從文件中讀取的字符串。
例:文件的 小部分:
#---------- #1 : ----------#
<MSG_INFO>
<message type="TextMessage" messageSelector="" originationTimestamp="" receiveTime="" jmsServerTimestamp="" jmsMsgExpiration="">
<header JMSDestinationType="Generic" JMSDeliveryMode="2" />
<properties>
<property name="messageTopic" type="String">xyz</property>
</properties>
</message>
BodyLength=1476
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
我不明白。你是說你有一個嵌入了XML'片段'的文本文件嗎? Java有多種可用於解析(格式良好)的XML的API。 –
@AndrewThompson說的。 「只有XML」是什麼意思?你能舉一個簡單的例子嗎? –
用戶是否要在輸入中輸入整個xml文件?然後CDATA吧! – Alfabravo