简体   繁体   中英

How to Specify (give an actual name) XML fields in Java (Apache CXF)

Operation is JAVA to WSDL. I am creating a SOAP Webservice.

I generated a SOAP webservice and the attributes look like this:

         <arg0>?</arg0>
         <!--Optional:-->
         <arg1>?</arg1>
         <!--Optional:-->
         <arg2>?</arg2>
         <!--Optional:-->
         <arg3>?</arg3>
         <!--Optional:-->
         <arg4>?</arg4>

What XML annotation should I use to specify them to look these like instead:

<name> </name>
<age> </age>
<location> </location>

Let's say

String age = "";
String name = "";
String location = "";

Do I use

@XmlAttribute(name="age")
String age = "";
@XmlAttribute(name="name")
String name = "";
@XmlAttribute(name="location ")
String location = "";

I use Apache CXF. Generate WebService -> yada -> yada in Eclipse.

Basically what Im asking is the XML keyword in charge of "renaming" Java fields fromg arg0 to something specific like "name".

I've not created a service with CXF, only a client but when using the Apache cxf-codegen-plugin to generate sources from the wsdl the annotation on the object's properties is @XmlElement(name = "age")

If a schema type is desired the annotation is @XmlSchemaType(name = "string") .

For enums it's @XmlEnumValue("THE VALUE")

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM