CSDN博客

img evilzydar

使用dom4j和XMLHTTP轻松解决多条记录操作

发表于2004/9/20 19:07:00  600人阅读

/////////////////////////////
// XML Http Function      //
////////////////////////////
function postXmlDocument(sUri, xmlDoc) {
   var xmlHttp = XmlHttp.create();
   var async = true;
   xmlHttp.open("POST", sUri, async);
   xmlHttp.setRequestHeader("Content-Type","text/xml");
   xmlHttp.setRequestHeader("charset","UTF-8");
   xmlHttp.onreadystatechange = function () {
      if (xmlHttp.readyState == 4)
         postHandleCallback(xmlHttp.responseText); // responseXML : XmlDocument
   }
   xmlHttp.send(xmlDoc);
}
Servlet端代码,只需要把xml流读进来,然后直接进行解析处理就可以了

  SAXReader xmlReader = new SAXReader();
  InputStream in = ServletActionContext.getRequest().getInputStream();
  document = xmlReader.read(in);

下面是对xml文档的遍历

for (Iterator i = root.elementIterator(modelName); i.hasNext();) {
    Element element = (Element) i.next();
    Object entityIns = instanceModel(modelName);
    Iterator subnodes = element.elementIterator();
    while (subnodes.hasNext()) {
     Element subnode = (Element) subnodes.next();
     dynamicPopulate(subnode.getName(), subnode.getText(), entityIns);
    }}

阅读全文
0 0

相关文章推荐

img
取 消
img