对象方法
document.write()
document.createElement_x(Tag)
document.getElementByIdx_x(ID)
document.getElementsByName(Name)
===============================================================================================================
试试,不过个人还是推荐使用dom4J,简单,速度快,dom4j+xpath方式解XML非常直观,比用Dom方式好很多。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
public
static
String XMLtoStr(Document document) {
String result =
null
;
if
(document !=
null
) {
StringWriter strWtr =
new
StringWriter();
StreamResult strResult =
new
StreamResult(strWtr);
TransformerFactory tfac = TransformerFactory.newInstance();
try
{
Transformer t = tfac.newTransformer();
t.setOutputProperty(OutputKeys.ENCODING,
"gb2312"
);
t.setOutputProperty(OutputKeys.INDENT,
"yes"
);
t.setOutputProperty(OutputKeys.METHOD,
"xml"
);
t.setOutputProperty(
"{http://xml.apache.org/xslt}indent-amount"
,
"4"
);
t.transform(
new
DOMSource(document.getDocumentElement()),
strResult);
}
catch
(Exception e) {
System.err.println(
"XML.toString(Document): "
+ e);
}
result = strResult.getWriter().toString();
}
return
result;
}
|
==================================================================================================