从 XML 文件中删除标题的简单方法 [英] A simple way to remove headers from XML files
本文介绍了从 XML 文件中删除标题的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从另一个程序生成的文件中删除非 xml 标签.
I need remove non-xml tags from file generated by another program.
文件是这样的:
Executing Command - Blah.exe ...
-----Command Output-----
HTTP/1.1 200 OK
Connection: close
Content-Type: text/xml
<?xml version="1.0"?>
<testResults>
<finalCounts>
<right>7</right>
<wrong>4</wrong>
<ignores>0</ignores>
<exceptions>0</exceptions>
</finalCounts>
</testResults>
Exit-Code: 15
如何在java中轻松删除非xml文本?
How to remove the non-xml text easily in java?
推荐答案
// getContent() returns the complete text to strip.
//
String s = getContent();
// Find the start of the XML content using the <?xml prefix.
//
int xmlIndex = s.indexOf( "<?xml" );
// Strip the non-XML header.
//
s = s.substring( xmlIndex );
// Find the last closing angle-bracket; should indicate end of the XML.
//
xmlIndex = s.lastIndexOf( ">" );
// Strip everything after the closing angle-bracket.
//
s = s.substring( 0, xmlIndex );
这篇关于从 XML 文件中删除标题的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文