易截截图软件、单文件、免安装、纯绿色、仅160KB

Struts2输出XML格式的Result

扩展Struts2--自定义String和XML格式的Result 



struts2虽然继承了webwork优秀的MVC分离,可是有很多地方让人百思不得其解!最让人离谱的是,返回的结果集中居然没有
String,xml这两种非常常用的类型。还是自己动手,丰衣足食:
第一种方式:使用“PlainText Result”
    先看官方文档对plain text结果的定义:“A result that send the content out as
plain text. Usefull typically when needed to display the raw content of
a JSP or Html file for example.”这是一个纯扯蛋的说法。。。貌似感觉只能返回jsp页面似的,最起码他误导了我。
    其实使用“PlainText Result” ,返回的结果是未进行格式和编码定义的字符串

什么意思?就类似于“FreeMarker Result” 
,返回一个*.ftl格式的模板,你完全可以在*.ftl写string,那么结果就是string;也可以在里面写xml,那么结果就是xml。
   举例如下:
<?
xml
 
version
=
"1.0"
 
encoding
=
"UTF-8"
 
?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
<
struts
>
    
<
package
 
name
=
"example"
 
namespace
=
"/example"
        
extends
=
"struts-default"
>
        
<
action
 
name
=
"outputXml"
  
method
=
"outxml"
 
class
=
"example.OutputXml"
>
            
<
result
 
name
=
"xmlMessage"
 
type
=
"plaintext"
>
</
result
>
        
</
action
>


相关文档:

XML文件绑定数据集控件操作

//数据绑定
    public void DataBind()
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(@"App_data/dbGuest.xml"));
&nbs ......

VB.NET中操作xml文件(插入节点、修改、删除)

已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
< ......

XML DTD XSD XSL XDR都有什么区别?

XML=可扩展标记语言(eXtensible Markup Language).
可扩展标记语言XML是一种简单的数据存储语言,使用一系列简单的标记描述数据,而这些标记可以用方便的方式建立,虽然XML占用的空间比二进制数据要占用更多的空间,但XML极其简单易于掌握和使用。
XML的简单使其易于在任何应用程序中读写数据,这使XML很快成为数据交换的 ......

xml与dataset(datatable)互转

引用类库:
 using System;
 using System.Data;
 using System.IO;
 using System.Xml;
using System.Text;
// 相应C#代码:
private string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号