手头正好需要一个xml转bean的工具和xml解析工具,网上实现很多,自己造一次轮子,一整套流程直接复制可用,一分钟实现转换加解析(xml转换使用idea实现,eclipse同样有工具,一搜一大把这里就不赘述了)。本文可转载,标注来源即可。
1.xml转xsd
1.1样例XML(persons.xml)
china
earth
investigation
1.2 利用idea将persons.xml生成persons.xsd
1.2.1首先打开persons.xml文件,右击点击Generate XSD Schema from XML File…
1.2.2 生成persons.xsd设置
需要注意Design type选项要选择local elements/types,确保在xsd转换bean时保证属性一致。
1.2.3生成persons.xsd文件
生成的persons.xsd文件预览