如何使用 jaxb 获取嵌套 xml 的对象。我有以下 XML -
<?xml version="1.0" ?>
<file>
<markups>
<markup>
<author>author</author>
<name>3w2fg</name>
<source>Mobile_iPad</source>
<createdOn>2013-05-20T11:22:23</createdOn>
<entities>
<entity>
<entityWdth>209</entityWdth>
<entityColor>
<red>127.5</red>
<green>0</green>
<blue>127.5</blue>
</entityColor>
<entityFillColor>
<red>227.5</red>
<green>0</green>
<blue>327.5</blue>
</entityFillColor>
<entityRadian>0</entityRadian>
<entityEndY>304</entityEndY>
<entityStX>438</entityStX>
<entityTypeCode>7</entityTypeCode>
<entityPageNo>1</entityPageNo>
<entityHt>183</entityHt>
<entityCenterX>542.5</entityCenterX>
<entityName>Rectangle</entityName>
<entityStY>121</entityStY>
<entityEndX>647</entityEndX>
<entityCenterY>212.5</entityCenterY>
</entity>
</entities>
</markup>
</markups>
<name>7987ab12-4915-49e5-8bbd-f98d6054ef6b.JPG</name>
<fileName>IMG_0008.JPG</fileName>
</file>
我正在使用 jaxb 来解组它,如下所示 -
JAXBContext jbContext = JAXBContext.newInstance(com.arc.markupinfo.generated.File.class);
com.arc.markupinfo.generated.ObjectFactory factory = new com.arc.markupinfo.generated.ObjectFactory();
com.arc.markupinfo.generated.File fileObj = factory.createFile();
Unmarshaller unmarshaller = jbContext.createUnmarshaller();
fileObj = (com.arc.markupinfo.generated.File) unmarshaller.unmarshal(new File(xmlLocation));
fileObj.getFileName();
该对象是使用除 entityColor.Red ... 和 entityFillColor.Red... 之外的所有值创建的。这些值以 0,0,0 的形式出现,而 xml 显示它具有正确的值