Unindent或线性化XML [英] Unindent or linearize XML
问题描述
我正在寻找一种在JAVA中线性化XML的快速方法
I'm looking for a fast way to linearize an XML in JAVA
我正在使用~2GB文件,因此排除了DOM。
Java targhet是1.5.0.22
我必须从xml生成一个由80bytes +换行符组成的文件。我必须在一个将由Cobol程序读取的DB2表中编写它。
I'm using ~2GB file so DOM is excluded. Java targhet is 1.5.0.22 I have to generate from an xml a file composed of 80bytes + newline. I have to write this in a DB2 table that will be read by a Cobol program.
在Cobol中,重要的是大小,因为数据从表中读取为CHAR,这意味着空行为80个空格。
In Cobol is important the size because the data are read as CHAR from table this implies the an empty rows is 80 spaces.
我读取文件字节到字节(我必须)但我可以使用内部临时缓冲来存储可能的序列以忽略
I read the file byte to byte(I must) but I can use internal temp bufferization to store the probably sequence to ignore
示例5字节af ascii文件
Example 5 bytes af ascii file
<a><b><c>psofpisogiosigpsfiogpo</c></b></a>
<a><b
><c>p
sofpi
sogio
sigps
fiogp
o</c>
</b><
/a>
问题与文件
<a>
<b>
<c>psofpisogiosigpsfiogpo</c>
</b>
</a>
<a>
<b
>
<c>ps
ofpis
ogios
igpsf
iogpo
</c>
<
/b>
</
a>
非线性化XML在表中创建空行或某些行未充分发挥其潜力。
The non linearized XML create empty rows in table or some rows that ar not used to their full potential.
这变成了付费cpu周期的丢失。来自HOST CICS环境
This became a lost of payd cpu cycle unde HOST CICS enviorment
如果我可以线性化我得到的文件如果文件是缩进的,那么相同的输出和XML保持相同的信息
If I can linearize the file i get same output if the file is indented or not and XML keep the same informations
任何想法?
推荐答案
private static final String XML_LINARIZATION_REGEX = "(>|>){1,1}(\\t)*(\\n|\\r)+(\\s)*(<|<){1,1}";
private static final String XML_LINARIZATION_REPLACEMENT = "$1$5";
public static String linarizeXml(String xml) {
return (xml!= null) ? xml.trim().replaceAll(XML_LINERIZATION_REGEX, XML_LINERIZATION_REPLACEMENT) : null;
}
这篇关于Unindent或线性化XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!