<types>
<xsd:schema targetNamespace="http://www.ibm.com/bpws4j/samples/echocomplex/types"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="phone">
<xsd:element name="areaCode" type="xsd:int"/>
<xsd:element name="exchange" type="xsd:string"/>
<xsd:element name="number" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
</types>
大概是类似于上面的代码,我要用Java对其建模,即我要创建一个这样的类:
public class type{
int areaCode;
String exchange;
String number;
...
}
我的问题是,能不能由程序解析上面的XML文档之后,自动创建一个类似于type的类?
type.setField("number","1234"); // 这时可以根据配置文件做一些校验.
String num=type.getField("number");因为你在代码期间是不可能知道Phone这个类型的.