用jaxb方法將xml(帶名稱空間xmlns)轉為java實體類
阿新 • • 發佈:2019-02-19
關於xml檔案轉為java實體類,如果不帶名稱空間 “<m:”,用jaxb的unmarshaller方法,還有註解@XmlRootElement 等方法可以轉成功,但是xml包含了"<m:"字首(名稱空間)就有問題。網上找了好久也沒能解決。還請高手幫我看下。謝謝
xml程式碼如下:
<?xml version="1.0" encoding="UTF-8"?> <!--週期抄表Response--> <ResponseMessage xmlns="http://iec.ch/TC57/2011/schema/message" xmlns:m="http://iec.ch/TC57/2011/ MeterReadings#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Payload> <m:MeterReadings> <m:MeterReading> <m:Meter> <m:mRID>3dc53ee5-777e-50b4-8699-a1c224f45f3d</m:mRID> <Names> <name>1</name> <NameType> <name>MeterType</name> </NameType> </Names> </m:Meter> <m:Readings> <m:timeStamp>2015-06-1T00:00:00+04:30</m:timeStamp> <m:value>2.6</m:value> <m:ReadingType ref="13.0.0.1.1.1.12.0.0.0.0.1.0.0.0.3.72.0"/> <m:timePeriod> <m:end>2015-06-1T00:00:00+04:30</m:end> <m:start>2015-05-1T00:00:00+04:30</m:start> </m:timePeriod> </m:Readings> </m:MeterReading> </m:MeterReadings> </Payload>
</ResponseMessage>