Understanding JAXB @XmlRootElement annotation

前端 未结 2 686
悲&欢浪女
悲&欢浪女 2021-02-01 23:22

I am using the tutorial here for understanding JAXB.

When the writer comes to create the root of the document, the writer begins as below:

//This sta         


        
2条回答
  •  逝去的感伤
    2021-02-02 00:09

    • @XmlRootElement annotation can be used to map a class or enum type to XML type.

    • When a top level class or an enum type is annotated with the @XmlRootElement annotation, then its value is represented as XML element in an XML document.

    • Follow the example given below to get more idea:

    Associate an element with XML Schema type

    // Example: Code fragment
     @XmlRootElement
     class Point {
        int x;
        int y;
        Point(int _x,int _y) {x=_x;y=_y;}
     }
    
     //Example: Code fragment corresponding to XML output
     marshal( new Point(3,5), System.out);
    
    
     
     
        3 
        5 
     
    

提交回复
热议问题