matsudakazumi / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Example of how to parse an element containing both attributes and a text-element value #273

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Which Google API and version (e.g. Google Calendar Data API version 2)?  
Contacts API version 2 (or 3)

What format (e.g. JSON, Atom)?
Atom

What Authentation (e.g. OAuth, OAuth 2, Android, ClientLogin)?
N/A

Java environment (e.g. Java 6, Android 2.3, App Engine 1.4.2)?
Java 6

Please provide any additional information below:

I am trying to parse data from the gData contacts feed.  In this feed, phone 
numbers are specified with both attributes as well as text values.   Example:
<gd:phoneNumber 
rel='http://schemas.google.com/g/2005#other'>123-123-1234</gd:phoneNumber>

I need to parse both the "rel" attribute as well as the text-element value.

To do this I have created the following class:
public class PhoneNumber {
    @Value
    public String value;    
    @Key("@rel")
    public String rel;
    @Key("@label")
    public String label;    
}

This gets the "rel" set correctly, but not the "value".   I was only guessing 
that the @Value attribute would give me the text-element value, but it 
apparently doesn't.  How can I do this?

Original issue reported on code.google.com by cw...@cloudsherpas.com on 17 Aug 2011 at 7:32

GoogleCodeExporter commented 9 years ago
use @Key("text()")

More details here:

http://javadoc.google-api-java-client.googlecode.com/hg/1.5.0-beta/com/google/ap
i/client/googleapis/xml/atom/package-summary.html

Original comment by yan...@google.com on 19 Aug 2011 at 12:19