flex如何获取java生成的xml格式数据

abrs561shgshg 2009-02-18 10:54:43
/*
* <?xml version="1.0" encoding="UTF-8"?>
* <root>
* <city>北京</city>
* <city>上海</city>
* </root>
*
*/

//以下为确定输出类型,定义输出变量
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();

//初始化各DocumentBuilderFactory变量
try {
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
doc = builder.newDocument();
root = doc.createElement("root");

Element city = doc.createElement("city");
city.appendChild(doc.createTextNode("北京"));
root.appendChild(city);

city = doc.createElement("city");
city.appendChild(doc.createTextNode("上海"));
root.appendChild(city);
doc.appendChild(root);

// XMLOutputter XMLOut = new XMLOutputter();
// // 输出 user.xml 文件;
// XMLOut.output(Doc, new FileOutputStream("user.xml"));

TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
DOMSource dom = new DOMSource(doc);
StreamResult result = new StreamResult(out);
t.setOutputProperty("encoding", "UTF-8");
// StringWriter sw=new StringWriter();
// StreamResult sr=new StreamResult(sw);
t.transform(dom, result);
out.flush();
out.close();



} catch (Exception e) {
throw new ABRSException("throw error!");
}
生成的xml数据是不是上面的 * <?xml version="1.0" encoding="UTF-8"?>
* <root>
* <city>北京</city>
* <city>上海</city>
* </root>
*
*/
数据啊,我在flex前台是这样获取该xml数据的:
private function listBmStationurlResult(event:ResultEvent){
var temp:XML=event.result as XML ;
trace(temp);
}但是输出的temp为null,是我生成的xml有问题还是我flex前台获取xml数据有问题???
...全文
454 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
adriano86426 2009-02-28
  • 打赏
  • 举报
回复
这里有 http://blog.csdn.net/adriano86426/archive/2009/02/23/3928454.aspx

使用Httpservice
abrs561shgshg 2009-02-24
  • 打赏
  • 举报
回复
就是不知道怎么测试后台生成的代码啊,本来我是用
var temp:XML=event.result as XML ;
trace(temp); 进行测试的,但是结果为null了
xiongzhijian 2009-02-18
  • 打赏
  • 举报
回复
有点晕,把代码贴出来就不管了?
后台的生成的数据有没有测试?

25,979

社区成员

发帖
与我相关
我的任务
社区描述
高性能WEB开发
社区管理员
  • 高性能WEB开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧