<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <MbfService> <output1> <MbfHeader> <ServiceCode>LMPCustLevelMgmt</ServiceCode> <Operation>queryLevelInfo</Operation> <UId>414d5120514d5f6c6f63616c202020203baa474c20012802</UId> <ServiceResponse> <Status>COMPLETE</Status> </ServiceResponse> </MbfHeader> <MbfBody> <appHeader> <getRecNum>1</getRecNum> <beginRecNum>0</beginRecNum> </appHeader> <body xsi:type="tr01010010Res" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <custNum>6002058692</custNum> <levelTypeStructList> <levelTypeStruct> <levelType>A1000020</levelType> <levelNum>B1000010</levelNum> </levelTypeStruct> </levelTypeStructList> </body> </MbfBody> </output1> </MbfService>
上面是使用JAXBContext解析出的报文,想把body节点中的xsi:type xmlns:xsi删除,google找出一篇文章,记录之:
Remove xsi:type after marshalling abstract class with hierarchy
If someone help me,that will be great. So I have a structure:
<span style="font-family:Courier New;font-size:12px;"><letters> <list> <name>Simon</name> <type>2</type> <passengerName>Johny</passengerName> <passengerSurname>Revelator</passengerSurname> </list> <list> <name>someName</name> <type>4</type> <fileURL>someUrl</fileURL> <specialNotes>specialNotes</specialNotes> </list> </letters></span>
For this structure I wrote Java Classes and they marshall and unmarshall it: Class A package com.edhex.testing;
import javax.xmlbindannotation.*; @XmlAccessorType(XmlAccessTypePROPERTY)@XmlSeeAlso({B.class, C})@XmlType abstractpublicclass A {int type; String name@XmlElement getType() return}void setType(thistype = getName setNamename }
Class Letters:
@XmlRootElementLettersList<A> list getList setListlist Class B:Bextends fileURL specialNotes getFileURL setFileURLfileURL getSpecialNotes setSpecialNotesspecialNotes Class C:CpassengerName passengerSurname getPassengerName setPassengerNamepassengerName getPassengerSurname setPassengerSurnamepassengerSurname Everything looks fine,but after marshalling which I do like this:staticmainString[] args C c new(); csetName("Simon");setType(2setPassengerName"Johny"setPassengerSurname"Revelator" B b B b4setFileURL"someUrl"setSpecialNotes"specialNotes""someName" list ArrayList>(add(cb letter Letters lettersetListlisttryFile file File"C:\file.xml"JAXBContext jaxbContext JAXBContextnewInstanceMarshaller jaxbMarshaller jaxbContextcreateMarshaller jaxbMarshallersetPropertyMarshallerJAXB_FORMATTED_OUTPUTtruemarshalletter fileSystemoutcatchJAXBException eprintStackTrace I get output like this:<letters> <list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:type"c"<name>Lasha</name><type>2</type><passengerName>Johny</passengerName><passengerSurname>Revelator</passengerSurname></list>"b"someName4<fileURL>someUrl</fileURL><specialNotes>specialNotes</specialNotes></letters>Question:How can I remove those: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="b" in each list tag? I know that JAXB will notify me with what type is it using,because originally mapping is using another type (A.class),but I don't need that information. Have somebody any ideas?
Answers
@H_576_403@ @H_31_404@