structuring things in XML file

前端 未结 1 857
庸人自扰
庸人自扰 2020-12-20 09:38

I want to have something below to save in the xml file

Question0 : What is ur name?
 Answer0: Tina
   Question0.0 : What are your hobbies?
           Answer0         


        
相关标签:
1条回答
  • 2020-12-20 10:29

    The easiest way is probably to use JAXB.

    It consists in writing JavaBeans holding the information (in your case, a Question and an Answer class, with the Question class holding a list of answers, and the answer class holding a (sub-)question).

    Then, you ave to annotate the classes to tell JAXB how to map the JavaBean properties to XML attributes or elements.

    And then you have to get a Marshaller which will transform your JavaBean tree into an XML document.

    The following page has a short tutorial over these steps. Googling for JAXB will lead you to a more exhaustive documentation: http://www.vogella.de/articles/JAXB/article.html#jaxb

    0 讨论(0)
提交回复
热议问题