JAXB multi-tier java and XML transformations

Source: Internet
Author: User
/**
 * * * * * *
package com.wonders.quartz.cocc.model.xml;

Import java.util.List;

Import Javax.xml.bind.annotation.XmlAttribute;
Import javax.xml.bind.annotation.XmlElement;
Import javax.xml.bind.annotation.XmlRootElement;

Import Com.wonders.quartz.cocc.model.vo.CoccListVo;
Import Com.wonders.quartz.cocc.model.vo.CoccReportVo;

/** 
 * @ClassName: Coccreportxml 
 * @Description: TODO (Describe the role of this class in one sentence) 
 * @author Zhoushun 
 * @date December 10, 2013 PM 2:31:33 
 *  
 *
/@XmlRootElement (name = "root") public
class Coccreportxml {
	@ XmlAttribute (name = "type") public
	String type= "Coccmetroweekreport";
	@XmlAttribute (name = "date") public
	String date= new Java.text.SimpleDateFormat ("Yyyy-mm-dd"). Format (new Java.util.Date ());
	@XmlElement (name = "List") public
	cocclistvo list;

	
	


/**
 * * * * * *
package com.wonders.quartz.cocc.model.vo;

Import java.util.List;

Import Javax.xml.bind.annotation.XmlAccessType;
Import Javax.xml.bind.annotation.XmlAccessorType;
Import javax.xml.bind.annotation.XmlElement;
Import javax.xml.bind.annotation.XmlRootElement;

/** 
 * @ClassName: Coccreport 
 * @Description: TODO (Describe the role of this class in one sentence) 
 * @author Zhoushun 
 * @date December 10, 2013 afternoon 2:12:33 
 *  
 *
/@XmlRootElement (name = "BBBB")
@XmlAccessorType ( Xmlaccesstype.field) Public
class Cocclistvo {
	@XmlElement (name = ' COCC ') public
	List<coccreportvo > list;
	
}


/** * * * * * * Package com.wonders.quartz.cocc.model.vo;
Import Javax.xml.bind.annotation.XmlAccessType;
Import Javax.xml.bind.annotation.XmlAccessorType;

Import javax.xml.bind.annotation.XmlRootElement;  
 /** * @ClassName: Coccreport * @Description: TODO (Describe the role of this class in one sentence) * @author Zhoushun * @date December 10, 2013 2:12:33 * */@XmlRootElement (name = "123") @XmlAccessorType (Xmlaccesstype.field) public class Coccreportvo {public String
	Id
	Public String title;
	public String Source;
	Public String Createtime;
	Public String Publishtime;
	public String URL;
	Public String GetId () {return id;
	public void SetId (String id) {this.id = ID;
	Public String GetTitle () {return title;
	public void Settitle (String title) {this.title = title;
	Public String GetSource () {return source;
	public void SetSource (String source) {This.source = source;
	Public String Getcreatetime () {return createtime; } public void Setcreatetime (String createtime) {This. createtime = Createtime;
	Public String Getpublishtime () {return publishtime;
	} public void Setpublishtime (String publishtime) {this.publishtime = Publishtime;
	Public String GetUrl () {return URL;
	public void SetUrl (String url) {this.url = URL;
 }
	
	
}


try{
			StringWriter writer = new StringWriter ();
			Jaxbcontext context = jaxbcontext.newinstance (coccreportxml.class);
			Marshaller m = Context.createmarshaller ();
			M.setproperty (Marshaller.jaxb_formatted_output, true); 
			M.setproperty (marshaller.jaxb_encoding, "GBK"); Prevent file Chinese garbled
			M.marshal (XML, writer);
			result = Writer.tostring ();
		} catch (Exception e) {result
			= ' none ';
		}


The node name that ultimately displays the XML string is based on the name on the node that contains the class externally.
Xml:

<?xml version= "1.0" encoding= "GBK" standalone= "yes"?> <root "date=" "2014-01-13"
Coccmetroweekreport ">
    <list>
        <cocc>
            <id>54844</id>
            <title> Shanghai Rail Transit network Operation Production Weekly (January 6, 2014-January 12, 2014) </title>
            <source>COCC</source>
            <createtime >2014-01-13</createTime>
            <publishTime>2014-01-13</publishTime>
            <url>http:// 10.1.44.18/stfb/node393/node1254/201401/con1050155.htm</url>
        </cocc>
    </list>
</root>


Xml:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.