【发布时间】:2012-08-10 06:52:47
【问题描述】:
我有以下 xml 字符串。我想将其转换为 java 对象,以将每个标签与该对象的字段映射。与标签名称相比,如果我可以引入不同的字段名称,那就更好了。我怎么能这样做?我正在查看 JAXB,但我仍然对“ns4:response”之类的部分和标签中的标签感到困惑。提前谢谢你...
<ns4:response>
<count>1</count>
<limit>1</limit>
<offset>1</offset>
<ns3:payload xsi:type="productsPayload">
<products>
<product>
<avgRating xsi:nil="true"/>
<brand>Candie's</brand>
<description>
<longDescription>
long descriptions
</longDescription>
<shortDescription>
short description
</shortDescription>
</description>
<images>
<image>
<altText>alternate text</altText>
<height>180.0</height>
<url>
url
</url>
<width>180.0</width>
</image>
</images>
<price>
<clearancePrice xsi:nil="true"/>
<regularPrice xsi:nil="true"/>
<salePrice>28.0</salePrice>
</price>
</product>
</products>
</ns3:payload>
</ns4:response>
【问题讨论】:
-
另外,有没有我可以自动将其转换为 Java 类...?
-
标签中的标签,这让我感到困惑吗?还有“
” -
我希望这不是 XML 字符串的全部内容,因为没有定义命名空间前缀(
ns4等),因此您将无法使用标准工具对其进行解析 -
你应该学会在提问之前搜索 SO