解组嵌套的xml数据,给出空值

时间:2017-11-27 14:23:10

标签: java soap jaxb jax-ws-customization

    <bas:person>

             <req:vehicleinfo>
                <!--Zero or more repetitions:-->
                <bas:item>
                   <sch:modelno>k10</sch:modelno>
                   <sch:type>bs4</sch:type>
                </bas:item>
 <bas:item>
                   <sch:modelno>k12</sch:modelno>
                   <sch:type>bs5</sch:type>
                </bas:item>
             </req:extensionInfo>
    </bas:person>

Assume namespace for bas is some http://xxxxx.person.com
 for req is http://xxxxx.request.com
 for bas http://xxxxx.bas.com
for sch http://xxxxx.sch.com

这里有车辆信息,因为我可能有多个值,在我的Java对象中,我需要将车辆信息作为数组来处理某些项目依赖项。

这是我的java类

 @XmlRootElement(name="person")
@XmlAccessorType(XmlAccessType.FIELD)
    public class Person implements Serializable{


        @XmlElement(name="vehicleinfo",namespace="http://xxxxx.request.com")
        private VehicleInfo[] vehicleinfo;


// getter & setter

    }

车辆信息

@XmlAccessorType(XmlAccessType.FIELD)
    public class  VehicleInfo{

        @XmlAttribute(name="modelno",namespace="http://xxxxx.sch.com")
        private String key;
        @XmlAttribute(name="type",namespace="http://xxxxx.sch.com")
        private String value;

 //getter and setter

    }

我正在使用以下代码进行解组

SOAPMessage message = MessageFactory.newInstance().createMessage(null,
                new ByteArrayInputStream(xmlInput.getBytes()));
        JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        Person person= (Person) jaxbUnmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());

但是获得车辆信息的关键和价值

0 个答案:

没有答案