DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Specifying XML Tag Attributes with CXF Rest Web Services

Specifying XML Tag Attributes with CXF Rest Web Services

Sandeep Bhandari user avatar by
Sandeep Bhandari
·
May. 21, 11 · Interview
Like (0)
Save
Tweet
Share
6.11K Views

Join the DZone community and get the full member experience.

Join For Free

CXF comes with a reference implementation of JSR-311which is the specification for Restful web services also known as JAX-RS.We can generate XML output using Rest web services using CXF framework. Please note that CXF is a framework which is being maintained by Apache foundation.

In order to have attributes in the various XML tags being generated by using CXF, one has to use the @XmlAttribute annotation to declare attributes for a particular xml element. Usually each unique tag in XML output corresponds to a single class in a CXF REST web service.

For using the @XmlAttribute annotation, one needs to import the class  javax.xml.bind.annotation.XmlAttribute

It is worth noting that the XmlAttribute class is available to you if you are using JDK 6. If you are using anything older  than JDK 6 then you can download the JSR-311 reference implementation jar from the following location:

http://download.java.net/maven/2/javax/ws/rs/jsr311-api/0.9/

Also the @XmlAttribute annotation can be used with a field or a javabean getter property method but not with both for the same field. What we mean here is that if you have a field named "empid" and corresponding getters and setters for empid as getEmpid and setEmpid then you should either use the attribute annotation with the string variable or the getter method but not both. If used with both, an exception about duplicate attributes will thrown.

Please not that if you make a member variable as the attribute in the XML output of CXF Restful web services then that member variable will not become a child of the tag being represented by the current class.

Here is the javadoc for @XmlAttribute annotation:http://download.oracle.com/javaee/5/api/javax/xml/bind/annotation/XmlAttribute.html

From http://extreme-java.blogspot.com/2011/05/specifying-xml-tag-attributes-with-cxf.html

XML Web Service Attribute (computing) REST

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 4 Best dApp Frameworks for First-Time Ethereum Developers
  • Best Practices for Writing Clean and Maintainable Code
  • How To Set Up and Run Cypress Test Cases in CI/CD TeamCity
  • Experts on How to Make Product Development More Predictable and Cost-Efficient

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: