开发者

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

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开发者_如何学Python ". 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!


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜