function addNewGood() {
var xml = '<?xml version="1.0" encoding="UTF-8"?>' + '\n';
xml = xml + '<data>' + '\n';
xml = xml + '<goods_attributes>' + '\n';
var nodeList = document.getElementsByTagName("input"); for ( var i = 0; i < nodeList.length; i++) {
if (nodeList[i].id.indexOf("GOODS_ATTRIBUTE_VALUE_") != -1
&& nodeList[i].type == "text") {
if (checkIsNotEmpty(nodeList[i].value)) {
var _index = nodeList[i].id.replace("GOODS_ATTRIBUTE_VALUE_",
""); xml = xml + '<goods_attribute>' + '\n'; xml = xml + '<goods_attribute_id><![CDATA['
+ $("#GOODS_ATTRIBUTE_ID_" + _index + "").val()
+ ']]></goods_attribute_id>' + '\n'; xml = xml + '<goods_attribute_title><![CDATA['
+ $("#GOODS_ATTRIBUTE_TITLE_" + _index + "").val()
+ ']]></goods_attribute_title>' + '\n'; xml = xml + '<goods_attribute_value><![CDATA['
+ $("#GOODS_ATTRIBUTE_VALUE_" + _index + "").val()
+ ']]></goods_attribute_value>' + '\n'; xml = xml + '</goods_attribute>' + '\n';

}
} xml = xml + '</goods_attributes>' + '\n';
xml = xml + '</data>';

sendAjaxHttpRequest(xml);
}function sendAjaxHttpRequest(xml) {
var url = projectPath + "/goodsAction!saveGoods.action"; createXmlHttp(); xmlHttpRequest.open("POST", url, true); xmlHttpRequest.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded"); xmlHttpRequest.onreadystatechange = ajaxCallback;
alert(xml)
xmlHttpRequest.send(xml);
}function ajaxCallback() {
if (xmlHttpRequest.readyState == 4) {
if (xmlHttpRequest.status == 200) {
if (xmlHttpRequest.responseText != 0) {
} else {
}
}
}
}function createXmlHttp() {
if (window.XMLHttpRequest) {
xmlHttpRequest = new XMLHttpRequest();
if (xmlHttpRequest.overrideMimeType) {
xmlHttpRequest.overrideMimeType("text ml");
}
} else if (window.ActiveXObject) {
try {
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
}
} @SuppressWarnings("unchecked")
public void getXmlParam(HttpServletRequest request) {
InputStream inputStream = null;
try {
inputStream = request.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SAXReader reader = new SAXReader();
Document document = null;
try {
document = reader.read(inputStream); //到这报错
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}我做了测试 读取实际存在xml文件如果xml文件为空或者只有xml头都报这个错
只有存在一对元素标签就不会报错
我把alert出来的xml数据拿到实际存在xml中没有错误
但ajax send时就出错
File inFile = new File("f:" + "\\" + "test.xml");
FileInputStream inStream = null;
try {
inStream = new FileInputStream(inFile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} InputStream inputStream = null;
try {
inputStream = request.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SAXReader reader = new SAXReader();
Document document = null;
try {
document = reader.read(inStream);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}