Java code
@Retention (Value=runtime)
@Target (Value=type)
Public @interface Xmlrootelement
@Inherited
@Retention (Value=runtime)
@Target (Value={package,type})
Public @interface Xmlaccessortype
Xmlrootelement: Maps A class or enumeration type to an XML element. A note in JAXB that is used to generate XML content from a Java class.When you annotate a top-level clas
determine the root element of the XML document. Therefore, the jaxbelement type instance can only be returned during parsing. In the first example, @ xmlrootelement (name = "book") anonation can be seen in the generated Java class, but not in the second example. This confirms what the API says:Note that when the root element name is unknown and the rootElement has@ Xsi: Type, The XML data is unmarshalledUsing that jaxb mapped class as the value ofJAX
I. jaxb common annotation for Java object and XML Conversion:
@ Xmltype
@ Xmlelement
@ Xmlrootelement
@ Xmlattribute
@ Xmlaccessortype
@ Xmlaccessororder
@ Xmltransient
@ Xmljavatypeadapter
Ii. Common annotation instructions
@ Xmltype
@ Xmltype is used in class annotations and is often used with @ xmlrootelement and @ xmlaccessortype. It has three attributes: name, proporder, and namespace. The
an XML element (called a wrapper) that wraps the array or collection. @XmlRootElement to map a Java class or enumeration type to an XML element. @XmlElement, a property of a Java class is mapped to an XML element with the same name as a property. @XmlAttribute, a property of a Java class is mapped to an XML attribute with the same name as a property.
1. @XmlType
@XmlType used in annotations of class classes, often in conjunction with @
> Levels > Extras > Extra > Type > 1 Type > Content > XX. Mm. xx Content > Extra > Extra > Type > 2 Type > Content > XX. Mm. xx Content > Extra > Extras > Bean >
Java Bean:
Import Java. util. arraylist; import Java. util. list; import javax. XML. BIND. annotation. xmlattribute; import javax. XML. BIND. annotation. xmlelement; im
Overview: Before the transformation of XML and Java objects to understand less, today Learning interface API just contact, so write down, beginners hope everyone forgive ha.1. Since it is a Java object and XML conversion, it is necessary to have a Java class to obtain the object, this example is mainly related to the boy class and the test run class2. Code2.1 Starting the first step of simple learning@XmlRootElement@XmlAccessorType (Xmlaccesstype.fiel
the related operation, recommend use.
Reference:
Https://jaxb.java.net/tutorial/index.html
Http://blog.bdoughan.com/2010/07/jpa-entities-to-xml-bidirectional.html
Http://blog.bdoughan.com/2013/03/moxys-xmlinversereference-is-now-truly.html
Top-level Elements:
xmlrootelement
A class that describes an XML element, "is" to be a top-level element, i.e., one of the can function as an XML document, s Hould is annotated with
methods:1Statecode READTRACKFROMGPX (track* track,Char*Path)2 {3cout"Start parsing gpx file ..."Endl;4 //reading GPX Files5 tixmldocument xmldoc (Path);6 xmldoc.loadfile ();7 //pointer to the element of the root node8tixmlelement*xmlrootelement;9 //pointer to the element of the child nodeTentixmlelement*xmlsubelement; One //Node Properties Atixmlattribute*rootattr; - //tixmlnode* pnode = NULL; - the //Get root node -
Marshaller and unmarshaller can be used to implement conversion between Java object and XML.
First, create a simple boy object.
[Java]
View plaincopyprint?
@ Xmlrootelement (name = "root ")
@ Xmlaccessortype (xmlaccesstype. Property)
Public class boy {
Private string name = "AA ";
Public String getname (){
Return name;
}
Public void setname (string name ){
This. Name = Name;
}
}
@XmlRootElem
JAXB (Java Architecture for XML Binding) is an industry standard and a technology that can produce Java classes based on XML schemas. In this process, JAXB also provides a way to reverse-generate the Java object tree from the XML instance document, and can re-write the contents of the Java object tree to the XML instance document. On the other hand, JAXB provides a quick and easy way to bind XML schemas to Java representations, making it easy for Java developers to combine XML data and processin
First, what is JAXB?
JAXB, or Java architecturefor XML Binding, is an industry standard that is a technology that can produce Java classes based on XML schemas. In this process, JAXB also provides a way to reverse-generate the Java object tree from the XML instance document, and can re-write the contents of the Java object tree to the XML instance document.
Ii. Introduction of annotations
1. The common annotations in JAXB that deal with conversion between Java and XML are:
1) @XmlType
2) @XmlEle
their combinations would be covered in this chapter, JAXB (JSR 222 Implement ation) is pretty complex and comprehensive. But if you just want to know how can interchange XML messages with your REST service, you is looking at right chapter .Lets start with simple example. Lets say we have class and Planet service which produces "planets"://Planet class@XmlRootElement Public classPlanet { Public intID; PublicString name; Public Doubleradius;}//Resour
SPRINGMVC web.xml Configuration I will not say ...
First you need to add the JSON jar package:Jackson-mapper-asl-*.jarJackson-core-asl-*.jar
In the Applicationcontext-servlet.xml file configuration, add the following registration default message converter:
Controller
@RequestMapping (method=requestmethod.get,value= "/rest")
@ResponseBody the public
User rest Test ( HttpServletRequest request, Uservo vo) {
User user = new user ();
User.setname ("YP");
User.se
A class that describes an XML element, a top-level element, i.e., one of the can function as an XML document, s Hould is annotated with XmlRootElement . Its optional elements is name and namespace . By default, the class name is used as the name.This annotation corresponds to a xsd:element construct being used at the outermost level of a XML schema. The sequence of Java, XML and schema snippets given below illustrates this relation.@
) FIELD in the Java class to XML. Other values include XmlAccessType. PROPERTY and XmlAccessType. NONE.
@ XmlAccessorOrder: Controls the sorting of attributes and fields in the JAXB binding class
@ XmlJavaTypeAdapter: use a custom adapter (that is, extend the abstract class XmlAdapter and overwrite the marshal () and unmarshal () methods) to serialize the Java class as XML.
@ XmlElementWrapper: for an array or set (that is, a member variable containing multiple elements), an XML element (call
of attributes and fields in the Jaxb binding class.
· XmlJavaTypeAdapter: uses a custom adapter (that is, extends the abstract class XmlAdapter and overwrites the marshal () and unmarshal () Methods) to serialize the Java class as Xml
· @ XmlElementWrapper: For arrays and collections (member variables containing multiple elements), generate an XML Element (called the wrapper) That wraps the array and binds it)
· @ XmlRootElement: maps Java classes or
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.