??xml version="1.0" encoding="utf-8" standalone="yes"?>
<page>1</page>
<pages>1</pages>
<perpage>100</perpage>
<total>19</total>
<photos>
<photo>
<id>ff8080810fc8ac78010fd3f158d40a52</id>
<owner>ff8080810f1a387b010f1a83d6530dfc</owner>
<title>Gmail-2</title>
<host>4</host>
<dir>20061230</dir>
<filename>231905_1463411198</filename>
</photo>
</photos>
</result>
单的alias一下就可以dg
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
XStream stream = new XStream();
stream.alias("result", YupooResult.class);
stream.alias("photo",YupooPhoto.class);
YupooResult result = (YupooResult)stream.fromXML(reader);
<photos>
<photo id="ff8080810fc8ac78010fd3f158d40a52"
owner="ff8080810f1a387b010f1a83d6530dfc" title="Gmail-2" host="4"
dir="20061230" filename="231905_1463411198" />
</photos>
</result>Hello,
I am not sure about the subject but here is what I needed help for:
XML:
<field name="value">I am a Field.</field>
I have already tried several structures and nothing seem to work.
Is this possible for XStream? :)
How is the Java class form to support this?
Thanks!
有h回答是看Converter的文档。果然找到答案了?br />自己写一个converter可以了?br />下面是我的converter
import java.util.ArrayList;
import java.util.List;
import com.jdkcn.yupoo.YupooPhoto;
import com.jdkcn.yupoo.YupooResult;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
/**
* @author <a href="mailto:rory.cn@gmail.com">somebody</a>
* @since Jan 16, 2007 6:12:35 PM
* @version $Id YupooResultConverter.java$
*/
public class YupooResultConverter implements Converter {
/* (non-Javadoc)
* @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object, com.thoughtworks.xstream.io.HierarchicalStreamWriter, com.thoughtworks.xstream.converters.MarshallingContext)
*/
public void marshal(Object obj, HierarchicalStreamWriter writer, MarshallingContext context) {
// FIXME unfinish.
}
/* (non-Javadoc)
* @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, com.thoughtworks.xstream.converters.UnmarshallingContext)
*/
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
YupooResult result = new YupooResult();
result.setPage(new Integer(reader.getAttribute("page")));
result.setPages(new Integer(reader.getAttribute("pages")));
result.setPerpage(new Integer(reader.getAttribute("perpage")));
result.setTotal(new Integer(reader.getAttribute("total")));
reader.moveDown();
List<YupooPhoto> photos = new ArrayList<YupooPhoto>();
while(reader.hasMoreChildren()) {
reader.moveDown();
YupooPhoto photo = new YupooPhoto();
photo.setDir(reader.getAttribute("dir"));
photo.setFilename(reader.getAttribute("filename"));
photo.setHost(reader.getAttribute("host"));
photo.setId(reader.getAttribute("id"));
photo.setOwner(reader.getAttribute("owner"));
photo.setTitle(reader.getAttribute("title"));
photos.add(photo);
reader.moveUp();
}
result.setPhotos(photos);
return result;
}
/* (non-Javadoc)
* @see com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.lang.Class)
*/
public boolean canConvert(Class clazz) {
return clazz.equals(YupooResult.class);
}
}
然后调用的地方修改一下就ok了?br />
stream.registerConverter(new YupooResultConverter());
stream.alias("result", YupooResult.class);
参?
http://xstream.codehaus.org/converter-tutorial.html
2007q??8日更新?br />q里感谢|友 Ivan ChenQ西滨) 的提C。原来新版的xstream可以单的解决了。在1.2.1的doc里面扑ֈ了这个两个方法?br />useAttributeFor
public void useAttributeFor(java.lang.String fieldName,
java.lang.Class type)
fieldName
- the name of the field
type
- the Class of the type to be rendered as XML attribute
XStream.InitializationException
- if no AttributeMapper
is available
useAttributeFor
public void useAttributeFor(java.lang.Class type)
type
- the Class of the type to be rendered as XML attribute
XStream.InitializationException
- if no AttributeMapper
is available
q两个方法都是从1.2开始支持的?br />也不用自己写converter了。这样就可以?br />
stream.useAttributeFor("page", Integer.class);
stream.useAttributeFor("pages", Integer.class);
stream.useAttributeFor("perpage", Integer.class);
stream.useAttributeFor("total", Integer.class);
stream.alias("photo", YupooPhoto.class);
stream.useAttributeFor("id", String.class);
stream.useAttributeFor("owner", String.class);
stream.useAttributeFor("title", String.class);
stream.useAttributeFor("host", String.class);
stream.useAttributeFor("dir", String.class);
stream.useAttributeFor("filename", String.class); 除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一? somebody(莫多)
]]>
先经q那个统计的filter然后再经q编码的filter。这L话编码的filter׃起作用了。只要吧~码的filter攑ֈ最前面没有问题了。改成这样就好?br />
以后大家一定要注意啊。顺序问题也是很重要的?br /> 除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一? somebody(莫多)
The top level element.
Attribute | Possible Value | Explanation |
---|---|---|
default-match-type (optional) | regex (default) | All rules and thier conditions will be processed using the Java Regular Expression engine (unless match-type is specified on a rule). |
wildcard | All rules and thier conditions will be processed using the Wildcard Expression engine (unless match-type is specified on a rule). | |
decode-using (optional) | utf8 (default) | When URL is decoded UTF-8 will be used. |
null | Do not decode. | |
[encoding] | Any string representing a supported character encoding eg, ISO-8859-1. See Java Charset Object for more info. | |
use-query-string (optional) | false (default) | The query string will not be appended to the url that the "from" element matches against. |
true | The query string will be appended to the url that the "from" element matches against. | |
use-context (optional) | false (default) | The context path will not be added to the url that the "from" element matches against. |
true | The context path will be added to the url that the "from" element matches against. |
除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一? somebody(莫多)
q样的话。所有的scheduler都不管用了。所以请大家要注意?br />
character-encoding | Resin 1.1 |
Specifies the default character encoding for the environment.
<web-app id='/'> <character-encoding>shift_jis</character-encoding> ... </web-app> |
q个是resin doc里面的我是在web-app-default里面加上了encoding的配|?/p>
希望对你的项目有帮助?/p>
除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一? somebody(莫多)
但是发现q样只有后面一个管?http://localhost:8080/passport/jsvm2)q个是可?可是(http://localhost:8080/community/jsvm2)׃?很是郁闷。只要后面的document-directory不是同一个目录就成?br /> 后来在resin的doc里面看到path的配|?/p>
Maps url patterns to real paths. If using a server like IIS, you may need to match the server's path aliases.
Attribute | Meaning | default |
---|---|---|
A pattern matching the url: | , , or||
url-regexp | A regular expression matching the url | |
real-path | The prefix of the real path. When used with | , allows substitution variables like .
<web-app id='/'> <path-mapping url-pattern='/resin/*' real-path='e:\resin'/> <path-mapping url-regexp='/~([^/]*)' real-path='e:\home$1'/> </web-app> |
Ҏq样的配|就ok了?/p>
启动服务Q抱错了?/p>
java.lang.IllegalArgumentExcep
at org.directwebremoting.impl
at org.directwebremoting.annotati
at org.directwebremoting.servlet
在DWR的Maillist里面搜烦了一下,q有{案Q原来DWR2.0 加入了JDK5的注?annotations).DwrServlet初始化的时候会L查注释的c,找不到就抱错了。如果你不用annotations也可以忽略掉q个错误。不q看hL不爽。有人提ZҎ。这样就ok了?/p>
除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一? somebody(莫多)