在ActionScript 3,如何去code从XML到ActionScript类? [英] In ActionScript 3, how to decode from xml to ActionScript class?
问题描述
在ActionScript 3,如何去code从XML到ActionScript类?
In ActionScript 3, how to decode from xml to ActionScript class ?
我可以连接code从ActionScript类XML使用XmlEn codeR。
I could encode from ActionScript class to xml by using XmlEncoder.
我当时使用XML架构是这样的。
The xml schema I used at that time is this.
[schema1.xsd]
[schema1.xsd]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="user">
<xs:sequence>
<xs:element name="id" type="xs:string" minOccurs="0"/>
<xs:element name="password" type="xs:string" minOccurs="0"/>
<xs:element name="userDate" type="xs:dateTime" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
此模式是通过使用POJO(User.java)不带注释的蚂蚁(schemagen)任务创建。
This schema is created by Ant(schemagen) task using POJO(User.java) with no annotations.
但我不能去$ C $从XML到ActionScript类使用此架构和XmlDe codeR℃。 (在正确的,我不能这样做从Object类型用户类型进行转换。)
But I could not decode from xml to ActionScript class by using this schema and XmlDecoder. (In correct, I can't be done casting from Object type to User type.)
我要不要放像@XmlRootElement或@XmlType任何注解的Java类。
I want not to put any annotations like @XmlRootElement or @XmlType in Java class.
不过,我需要的ActionScript客户端编组和解组模式文件。
However, I need a schema file for client side of ActionScript to marshal and unmarshall.
请告诉我,任何解决方案或实例...
Please tell me any solutions or examples...
推荐答案
下面的类:
import java.util.Date;
public class User {
private String id;
private String password;
private Date userDate;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getUserDate() {
return userDate;
}
public void setUserDate(Date userDate) {
this.userDate = userDate;
}
}
可用于解组下面的XML:
Can be used to unmarshal the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<id>123</id>
<password>foo</password>
<userDate>2011-01-07T09:15:00</userDate>
</root>
使用下面的code,而不需要任何注释上的用户等级:
Using the following code without requiring any annotations on the User class:
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(User.class);
StreamSource source = new StreamSource("input.xml");
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<User> root = unmarshaller.unmarshal(source, User.class);
User user = root.getValue();
System.out.println(user.getId());
System.out.println(user.getPassword());
System.out.println(user.getUserDate());
}
}
这篇关于在ActionScript 3,如何去code从XML到ActionScript类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!