When using google-api-java-client , I can't get to parse attributes of node elements. Can anyone tell me how to use it?

StackOverflow https://stackoverflow.com/questions/5020461

Question

On google-api-java-client exists an annotation @Key that it's used for parsing nodes on an XML. I received an answer from analytics service that contains several nodes that start with "dxp:property ". I only need the node that has the attribute name="ga:accountName" for getting the value of another attribute on the same node. But, I don't know if it exists an implementation on the library that google provided for parsing attributes, and I can't find any information on the documentation.

Does someone knows something about this?

Thanks!

Was it helpful?

Solution

Founded a way to do this! First, make a List of ProfileItems as an attribute of a class such as:

public class Profile {

    @Key("dxp:property")
    public List<ProfileItem> profiles;

}

Where ProfileItem is defined as:

public class ProfileItem {

    @Key("@name")
    public String name;

    @Key("@value")
    public String value;

}

The @ in the String of the Key annotation marks that name and value are attributes at the node dxp:property.

With this, now I can look for the name attribute that I want, that is ga:accountName.

See you!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top