Struts2Êä³öXML¸ñʽµÄResult
À©Õ¹Struts2--×Ô¶¨ÒåStringºÍXML¸ñʽµÄResult
struts2ËäÈ»¼Ì³ÐÁËwebworkÓÅÐãµÄMVC·ÖÀ룬¿ÉÊÇÓÐºÜ¶àµØ·½ÈÃÈ˰Ù˼²»µÃÆä½â£¡×îÈÃÈËÀëÆ×µÄÊÇ£¬·µ»ØµÄ½á¹û¼¯ÖоÓȻûÓÐ
String£¬xmlÕâÁ½Öַdz£³£ÓõÄÀàÐÍ¡£»¹ÊÇ×Ô¼º¶¯ÊÖ£¬·áÒÂ×ãʳ£º
µÚÒ»ÖÖ·½Ê½£ºÊ¹ÓÓ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Îļþ£¨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>
< ......
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
£¨1£©Ê¹ÓÃJDOMÊ×ÏÈÒªÖ¸¶¨Ê¹ÓÃʲô½âÎöÆ÷¡£È磺
SAXBuilder builder=new SAXBuilder(false) ......
ʲôÊÇ XML?
XML Ö¸¿ÉÀ©Õ¹±ê¼ÇÓïÑÔ£¨EXtensible Markup Language£©
XML ÊÇÒ»ÖÖ±ê¼ÇÓïÑÔ£¬ºÜÀàËÆ HTML
XML µÄÉè¼Æ×ÚÖ¼ÊÇ´«ÊäÊý¾Ý£¬¶ø·ÇÏÔʾÊý¾Ý
XML ±êǩûÓб»Ô¤¶¨Òå¡£ÄúÐèÒª×ÔÐж¨Òå±êÇ©¡£
XML ±»Éè¼ÆÎª¾ßÓÐ×ÔÎÒÃèÊöÐÔ¡£
XML ÊÇ W3C µÄÍÆ¼ö±ê×¼
XML Óë HTML µÄÖ÷Òª²îÒì
XML ²»ÊÇ HTML µÄÌæ´ú¡£
XML ºÍ HTML Ϊ² ......
ÒýÓÃÀà¿â£º
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
......
ÔÌù£ºhttp://topic.csdn.net/u/20100412/14/f6941844-e9bf-4ed7-a0c2-bef03d775783.html?70615
declare @data xml=
'<root>
<SaleMan>
<SaleManId>1</SaleManId>
<SaleManCode>001</SaleManCode>
<Nodes>
<Node>
< ......