我解组了一个XML来创建一个java对象。
XML -
<RibMessages
xmlns="http://www.oracle.com/retail/integration/rib/RibMessages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.oracle.com/retail/integration/rib/RibMessages http://kvm-oel-55-64-4:7780/rib-func-artifact/integration/xsd/RibMessages.xsd" >
<ribMessage>
<family>Items</family>
<type>ItemCre</type>
<id>100007066</id>
<ribmessageID>ItemsToItmHYB_tafr_1|2012.07.10 18:45:58.874|143</ribmessageID>
<routingInfo>
<name>tran_level_ind</name>
<value>Y</value>
</routingInfo>
<publishTime>2012-07-10 18:45:58.886 GMT+05:30</publishTime>
<messageData><ItemDesc xmlns="http://www.oracle.com/retail/integration/base/bo/ItemDesc/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><ns1:ItemHdrDesc xmlns:ns1="http://www.oracle.com/retail/integration/base/bo/ItemHdrDesc/v1" ><ns1:item>100007066</ns1:item><ns1:item_number_type>ITEM</ns1:item_number_type><ns1:pack_ind>N</ns1:pack_ind><ns1:item_level>1</ns1:item_level><ns1:tran_level>1</ns1:tran_level><ns1:dept>2102</ns1:dept><ns1:dept_name>Men&apos;s Classics</ns1:dept_name><ns1:class>2</ns1:class><ns1:class_name>Bottoms</ns1:class_name><ns1:subclass>2</ns1:subclass><ns1:sub_name>Casual Trousers</ns1:sub_name><ns1:status>A</ns1:status><ns1:item_desc>Test</ns1:item_desc><ns1:short_desc>Test</ns1:short_desc><ns1:desc_up>TEST</ns1:desc_up><ns1:primary_ref_item_ind>N</ns1:primary_ref_item_ind><ns1:retail_zone_group_id>1</ns1:retail_zone_group_id><ns1:cost_zone_group_id>1000</ns1:cost_zone_group_id><ns1:standard_uom>EA</ns1:standard_uom><ns1:merchandise_ind>Y</ns1:merchandise_ind><ns1:store_ord_mult>E</ns1:store_ord_mult><ns1:forecast_ind>N</ns1:forecast_ind><ns1:catch_weight_ind>N</ns1:catch_weight_ind><ns1:const_dimen_ind>N</ns1:const_dimen_ind><ns1:simple_pack_ind>N</ns1:simple_pack_ind><ns1:contains_inner_ind>N</ns1:contains_inner_ind><ns1:sellable_ind>Y</ns1:sellable_ind><ns1:orderable_ind>Y</ns1:orderable_ind><ns1:unit_retail>83.33</ns1:unit_retail><ns1:gift_wrap_ind>N</ns1:gift_wrap_ind><ns1:ship_alone_ind>N</ns1:ship_alone_ind><ns1:perishable_ind>N</ns1:perishable_ind><ns1:item_xform_ind>N</ns1:item_xform_ind><ns1:inventory_ind>Y</ns1:inventory_ind><ns1:notional_pack_ind>N</ns1:notional_pack_ind><ns1:soh_inquiry_at_pack_ind>N</ns1:soh_inquiry_at_pack_ind><ns1:purchase_type>N</ns1:purchase_type></ns1:ItemHdrDesc><ns2:ItemSupDesc xmlns:ns2="http://www.oracle.com/retail/integration/base/bo/ItemSupDesc/v1" ><ns2:item>100007066</ns2:item><ns2:supplier>2400</ns2:supplier><ns2:primary_supp_ind>Y</ns2:primary_supp_ind><ns2:pallet_name>PAL</ns2:pallet_name><ns2:case_name>CS</ns2:case_name><ns2:inner_name>INR</ns2:inner_name><ns2:direct_ship_ind>N</ns2:direct_ship_ind></ns2:ItemSupDesc><ns3:ItemSupCtyDesc xmlns:ns3="http://www.oracle.com/retail/integration/base/bo/ItemSupCtyDesc/v1" ><ns3:item>100007066</ns3:item><ns3:supplier>2400</ns3:supplier><ns3:origin_country_id>US</ns3:origin_country_id><ns3:primary_supp_ind>Y</ns3:primary_supp_ind><ns3:primary_country_ind>Y</ns3:primary_country_ind><ns3:unit_cost>25</ns3:unit_cost><ns3:supp_pack_size>1</ns3:supp_pack_size><ns3:inner_pack_size>1</ns3:inner_pack_size><ns3:round_lvl>C</ns3:round_lvl><ns3:packing_method>HANG</ns3:packing_method><ns3:default_uop>EA</ns3:default_uop><ns3:ti>1</ns3:ti><ns3:hi>1</ns3:hi><ns3:cost_uom>EA</ns3:cost_uom></ns3:ItemSupCtyDesc><ns4:ItemSupCtyMfrDesc xmlns:ns4="http://www.oracle.com/retail/integration/base/bo/ItemSupCtyMfrDesc/v1" ><ns4:item>100007066</ns4:item><ns4:supplier>2400</ns4:supplier><ns4:manufacturer_ctry_id>US</ns4:manufacturer_ctry_id><ns4:primary_manufacturer_ctry_ind>Y</ns4:primary_manufacturer_ctry_ind></ns4:ItemSupCtyMfrDesc></ItemDesc></messageData>
<customData></customData>
<customFlag>F</customFlag>
</ribMessage>
</RibMessages>
我的代码:
final ByteArrayInputStream ribMessagesString = new ByteArrayInputStream(xmlString.getBytes());
JAXBContext jaxbContext = JAXBContext.newInstance(RibMessages.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
final RibMessages ribMessages = (RibMessages) jaxbUnmarshaller.unmarshal(ribMessagesString);
这很好用,但是这样创建的对象之一包含一个String(messageData),它又是XML内容,它包含转义字符。消息XML需要再次解析。任何建议我们如何避免这种字符编码,所以,我想在消息数据中看到“not&amp; quot。”
由于