JAXB

2016-05-15 6 views
0

を使用してJavaオブジェクトにXMLを解析中にエラーを取得I次のXMLファイルを持っている:私はJAXBのアンマーシャラーを使用してJavaオブジェクトにこれを解析しようとしているJAXB

<?xml version="1.0" standalone="yes"?> 
<interestRateCurve> 
    <effectiveasof>2016-04-27</effectiveasof> 
    <currency>JPY</currency> 
    <baddayconvention>M</baddayconvention> 

    <deposits> 
    <daycountconvention>ACT/360</daycountconvention> 
    <snaptime>2016-04-26T07:00:00.000Z</snaptime> 
    <spotdate>2016-04-29</spotdate> 

    <calendars> 
     <calendar>TYO</calendar> 
    </calendars> 

    <curvepoint> 
     <tenor>1M</tenor> 
     <maturitydate>2016-05-30</maturitydate> 
     <parrate>-0.00066</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>2M</tenor> 
     <maturitydate>2016-06-29</maturitydate> 
     <parrate>-0.00042</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>3M</tenor> 
     <maturitydate>2016-07-29</maturitydate> 
     <parrate>-0.000386</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>6M</tenor> 
     <maturitydate>2016-10-31</maturitydate> 
     <parrate>-0.000114</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>1Y</tenor> 
     <maturitydate>2017-04-28</maturitydate> 
     <parrate>0.000758</parrate> 
    </curvepoint> 

    </deposits> 

    <swaps> 
    <fixeddaycountconvention>ACT/365</fixeddaycountconvention> 
    <floatingdaycountconvention>ACT/360</floatingdaycountconvention> 
    <fixedpaymentfrequency>6M</fixedpaymentfrequency> 
    <floatingpaymentfrequency>6M</floatingpaymentfrequency> 
    <snaptime>2016-04-26T07:00:00.000Z</snaptime> 
    <spotdate>2016-04-29</spotdate> 

    <calendars> 
     <calendar>TYO</calendar> 
    </calendars> 

    <curvepoint> 
     <tenor>2Y</tenor> 
     <maturitydate>2018-04-29</maturitydate> 
     <parrate>-0.0016</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>3Y</tenor> 
     <maturitydate>2019-04-29</maturitydate> 
     <parrate>-0.001663</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>4Y</tenor> 
     <maturitydate>2020-04-29</maturitydate> 
     <parrate>-0.001388</parrate> 
    </curvepoint> 
    <curvepoint> 
     <tenor>5Y</tenor> 
     <maturitydate>2021-04-29</maturitydate> 
     <parrate>-0.000963</parrate> 
    </curvepoint> 
    <curvepoint> 
     <tenor>6Y</tenor> 
     <maturitydate>2022-04-29</maturitydate> 
     <parrate>-0.000475</parrate> 
    </curvepoint> 
    <curvepoint> 
     <tenor>7Y</tenor> 
     <maturitydate>2023-04-29</maturitydate> 
     <parrate>-0.0000063</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>8Y</tenor> 
     <maturitydate>2024-04-29</maturitydate> 
     <parrate>0.000425</parrate> 
    </curvepoint> 
    <curvepoint> 
     <tenor>9Y</tenor> 
     <maturitydate>2025-04-29</maturitydate> 
     <parrate>0.000813</parrate> 
    </curvepoint> 
    <curvepoint> 
     <tenor>10Y</tenor> 
     <maturitydate>2026-04-29</maturitydate> 
     <parrate>0.0012</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>12Y</tenor> 
     <maturitydate>2028-04-29</maturitydate> 
     <parrate>0.002038</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>15Y</tenor> 
     <maturitydate>2031-04-29</maturitydate> 
     <parrate>0.00315</parrate> 
    </curvepoint> 
    <curvepoint> 
     <tenor>20Y</tenor> 
     <maturitydate>2036-04-29</maturitydate> 
     <parrate>0.004588</parrate> 
    </curvepoint> 

    <curvepoint> 
     <tenor>30Y</tenor> 
     <maturitydate>2046-04-29</maturitydate> 
     <parrate>0.005688</parrate> 
    </curvepoint> 
    </swaps> 
</interestRateCurve> 

を。私のクラスは次のとおりです。

InterestRateCurves.java:

​​

Deposits.java:

package IRCurves; 

import java.util.List; 

import javax.xml.bind.annotation.XmlElement; 


    public class Deposits { 
     private String daycountconvention; 
     private String snaptime; 
     private String spotdate; 
     private List<Calenders> calenders; 
     private List<Curvepoint> curvepoint; 

     public Deposits() {} 

     public Deposits(String daycountconvention, String snaptime, String spotdate, List<Calenders> calenders, List<Curvepoint> curvepoint) { 
      super(); 
      this.daycountconvention = daycountconvention; 
      this.snaptime = snaptime; 
      this.spotdate = spotdate; 
      this.calenders = calenders; 
      this.curvepoint = curvepoint; 
     } 
     public String getDaycountconvention() { 
      return daycountconvention; 
     } 
     public void setDaycountconvention(String daycountconvention) { 
      this.daycountconvention = daycountconvention; 
     } 
     public String getSnaptime() { 
      return snaptime; 
     } 
     public void setSnaptime(String snaptime) { 
      this.snaptime = snaptime; 
     } 
     public String getSpotdate() { 
      return spotdate; 
     } 
     public void setSpotdate(String spotdate) { 
      this.spotdate = spotdate; 
     } 

     @XmlElement 
     public List<Calenders> getCalenders() { 
      return calenders; 
     } 
     public void setCalenders(List<Calenders> calenders) { 
      this.calenders = calenders; 
     } 

     @XmlElement 
     public List<Curvepoint> getCurvepoint() { 
      return curvepoint; 
     } 
     public void setCurvepoint(List<Curvepoint> curvepoint) { 
      this.curvepoint = curvepoint; 
     } 

     } 

および同様の他のPOJOクラス。

package IRCurves; 

    import java.io.File; 
    import java.util.List; 

    import javax.xml.bind.JAXBContext; 
    import javax.xml.bind.JAXBException; 
    import javax.xml.bind.Unmarshaller; 

    public class XmlToObject { 
     public static void main(String[] args) { 

     try { 

      File file = new File("InterestRates.xml"); 
      JAXBContext jaxbContext = JAXBContext.newInstance(InterestRateCurves.class); 

      Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 
      InterestRateCurves que= (InterestRateCurves) jaxbUnmarshaller.unmarshal(file); 

      System.out.println(que.getEffectiveasof()+" "+que.getCurrency()+" "+que.getBaddayconvention()); 
      System.out.println("Deposits:"); 
      List<Deposits> list=que.getDeposits(); 
      for(Deposits ans:list) 
       { 
       System.out.println(ans.getDaycountconvention()+" "+ans.getSnaptime()+" "+ans.getSpotdate()); 
       System.out.println("Calenders:"); 
       List<Calenders> list1=ans.getCalenders(); 
       for(Calenders cal:list1) 
        System.out.println(cal.getCalender()); 
       System.out.println("Curvepoint:"); 
       List<Curvepoint> list2=ans.getCurvepoint(); 
       for(Curvepoint curve:list2) 
        System.out.println(curve.getTenor()+" "+curve.getMaturitydate()+" "+curve.getParrate()); 

       } 

      System.out.println("Swaps:"); 
      List<Swaps> list3=que.getSwaps(); 
      for(Swaps swap:list3) 
       { 
       System.out.println(swap.getFixeddaycountconvention()+" "+swap.getFloatingdaycountconvention()+" "+swap.getFixedpaymentfrequency()+" "+swap.getFloatingpaymentfrequency()+" "+swap.getSnaptime()+" "+swap.getSpotdate()); 
       System.out.println("Calenders:"); 
       List<Calenders> list1=swap.getCalenders(); 
       for(Calenders cal:list1) 
        System.out.println(cal.getCalender()); 
       System.out.println("Curvepoint:"); 
       List<Curvepoint> list2=swap.getCurvepoint(); 
       for(Curvepoint curve:list2) 
        System.out.println(curve.getTenor()+" "+curve.getMaturitydate()+" "+curve.getParrate()); 

       } 

      } catch (JAXBException e) { 
      e.printStackTrace(); 
      } 

     } 
    } 

しかし、私は次のエラーを取得しています::マイXMLToObject.javaがある

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"interestRateCurve"). Expected elements are <{}interestRateCurves> 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:243) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:238) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1048) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:483) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:465) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:378) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:604) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3122) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) 
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117) 
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848) 
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777) 
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) 
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) 
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203) 
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:175) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:162) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:171) 
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:189) 
    at IRCurves.XmlToObject.main(XmlToObject.java:19) 

それが何を意味するのかを教えてください?

答えて

0

@Blise Douglasの答えをthis questionにしてください。理由と解決方法を説明しています。

the {} portion refers to that qualified name not having the namespace URI portion set.