JAXB详细解组

时间:2016-08-02 17:47:29

标签: java xml jaxb unmarshalling

我是jaxb用法的新手,我能够将带有xml注释的java类编组为.xml,但是在解组时无法检索数据。当我对我的unmarshalled数据执行sysout时,它会打印上下文的地址而不是实际值。我不确定我哪里出错了。

.logoSvg {

  &:hover {

    &:first-child {
      animation-name: someAnimation;
      animation-iteration-count: infinite;
    }

    &:last-child {
      animation-name: someAnimation;
      animation-iteration-count: infinite;
    }
  }
}

@keyframes someAnimation {
  0%: {transform: some transformation};
  100%: {transform: some transformation};
}

此外,我想了解更多关于" jaxb context"等词语的内容。和" java模型/ java模型类"在解组xml文档时生成的以及它如何进入图片。

提前致谢!

1 个答案:

答案 0 :(得分:0)

尝试如下。

尝试{

    File file = new File("C:\\file.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);

    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    Customer customer = (Customer) jaxbUnmarshaller.unmarshal(file);
    System.out.println(customer);

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