2010-09-09 51 views
1

我使用Eclipse来构建Android应用程序。因为我用强烈的Web服务,我希望能够从XML架构创建一些POJO的简单的XML架构到POJO转换器

例如:

<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/VO.Service.Entities" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/VO.Service.Entities" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:complexType name="TrackCategories"> 
    <xs:sequence> 
     <xs:element minOccurs="0" maxOccurs="unbounded" name="Category" nillable="true" type="tns:CategoryInfo" /> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:element name="TrackCategories" nillable="true" type="tns:TrackCategories" /> 
    <xs:complexType name="CategoryInfo"> 
    <xs:sequence> 
     <xs:element minOccurs="0" name="CategoryName" nillable="true" type="xs:string" /> 
     <xs:element minOccurs="0" name="Id" type="xs:int" /> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:element name="CategoryInfo" nillable="true" type="tns:CategoryInfo" /> 
</xs:schema> 

我希望能够创建下面的类

public class CategoryInfo { 

public String CategoryName; 
public Integer Id; 

public String getCategoryName() { 
    return CategoryName; 
} 


public void setCategoryName(String value) { 
    this.CategoryName = value; 
} 

public Integer getId() { 
    return Id; 
} 

public void setId(Integer value) { 
    this.Id = value; 
} 

} 

由于就那么简单。没有约束力,没有评论只是一个普通的类。我已经尝试过Eclipse的JABX插件,但生成的类有很多我不需要的注释和类型。

任何解决方案?

回答

1

我已经使用apache的XMLBean - 生成了相当不错的类。

+0

我看到此答案后尝试使用XML bean。 XML Beans似乎已经过时了,似乎没有正确处理Java枚举,并且生成的对象不是上面要求的POJO。 – grbonk 2011-11-18 15:24:32

0

如果您需要mo Cast,蓖麻是较重的提升解决方案。