-
package
import
import putStream;
import
tFoundException;
import tputStream;
import ption;
import tream;
import ist;
import
import p;
import or;
import
import
import
import ntBuilder;
import ntBuilderFactory;
import ormer;
import
ormerFactory;
import rce;
import Result;
import nt;
import t;
import st;
import 64Encoder;
public class XmlWord {
private Map
public Map
return dataMap;
}
public void setDataMap(Map
p = dataMap;
}
/**
*
设置标识值
* @param tagList
标识
*
@param dataList
数据
* @param dataMap
*/
public void
setData(List
Iterator
Iterator
while(t()){
((), ());
}
}
/**
* <
/p>
载入一个
xml
文档
* @param filename
文件路径
*
@return
成功返回
Document
< br>对象,失败返回
null
*/
public Document LoadXml(String
filename){
Document doc =
null;
try {
DocumentBuilderFactory factory =
tance();
DocumentBuilder
builder = umentBuilder();
doc =
(Document) (new File(filename));
n(doc);
} catch
(Exception e) {
n(
载入
xml
文件时出错
tackTrace();
}
return doc;
}
/**
*
图片转码
*
@return
返回图片
base64
字符串
*
@throws Exception
*/
public String getImageStr(String
imgFile){
InputStream in = null;
BASE64Encoder encoder = null;
byte[] data = null;
try
{
in = new FileInputStream(imgFile);
} catch (FileNotFoundException e) {
p>
n(
文件没找到!
tackTrace();
}
try
{
data = new byte[ble()];
(data);
();
}
catch (IOException e) {
tackTrace();
}
encoder = new
BASE64Encoder();
return (data);
}
/**
* doc2XmlFile
*
将
Document
对象保存为一个
xml
文件
* @return
true:
保存成功
flase:
失败
* @param
filename
保存的文件名
* @param document
需要保存的
document
对象
*/
public boolean doc2XmlFile(Document
document,String filename)
{
boolean flag = true;
try{
TransformerFactory
transFactory = tance();
Transformer transformer =
nsformer();
DOMSource source=new DOMSource();
e(document);
StreamResult result=new
StreamResult();
FileOutputStream
fileOutputStream = new FileOutputStream(filename);
putStream(fileOutputStream);
orm(source, result);
();
}catch(Exception ex){
flag = false;
tackTrace();
}
return flag;
}
/**
*
替换标识内容:单个文本标记
* @param element
要替换内容的节点
* @param tag
标识名称
* @param data
替换参数
*
@return
返回替换后的节点
* @throws Exception
*/
public Element
replaceTagContext(Object
element,String tag,String data){