如何在 google-api-java-client 中创建表示复杂 xml 标记结构的类
使用 google-api-java-client 我收集到该库根据您创建的类和您创建的密钥来解析 xml。例如:如果您有以下 XML:
<entry test="ok">
<link name="somewhere.org"/>
</entry>
那么您可以拥有这两个类:
public class Entry
{
@Key("@test")
public String test;
@Key("link")
public Link link;
}
public class Link
{
@Key("name")
public String name;
}
并且库将解析 xml 并创建适当的类(如果我理解正确的话)
如果是这种情况,如何表示 xml 标签既具有属性又具有值?示例:
<entry test="ok">
<link name="somewhere.org">SomeValue</link>
</entry>
特别是,我试图表示如下所示的记录,以便我可以将其插入到谷歌文档电子表格中:
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:gs="http://schemas.google.com/spreadsheets/2006">
<title>Darcy</title>
<gs:field name='Birthday'>2/10/1785</gs:field>
<gs:field name='Age'>28</gs:field>
<gs:field name='Name'>Darcy</gs:field>
<gs:field name='CanVote'>No</gs:field>
</entry>
另外,此记录在哪里?我找不到文档,但也许我只是没有找对地方。
Using the google-api-java-client I have gathered that the library parses the xml based on the classes you create and the keys you make. For example: if you have the following XML:
<entry test="ok">
<link name="somewhere.org"/>
</entry>
Then you could have these two classes:
public class Entry
{
@Key("@test")
public String test;
@Key("link")
public Link link;
}
public class Link
{
@Key("name")
public String name;
}
And the library would parse the xml and create the appropriate classes (if I understand it correctly)
If that is the case, how does one represent an xml tag that has both attributes and a value? Example:
<entry test="ok">
<link name="somewhere.org">SomeValue</link>
</entry>
In particular I'm trying to represent a record such as the following so I can insert it into a google docs spreadsheet:
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:gs="http://schemas.google.com/spreadsheets/2006">
<title>Darcy</title>
<gs:field name='Birthday'>2/10/1785</gs:field>
<gs:field name='Age'>28</gs:field>
<gs:field name='Name'>Darcy</gs:field>
<gs:field name='CanVote'>No</gs:field>
</entry>
Also, where is this documented? I can't find the documentation but perhaps I'm just not looking in the right place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
google-api-java-client< 中有关 XML 数据模型的最佳文档/a> 库是 XML JavaDoc。
与 name 属性一起使用的 @Key 注释是“@name”。所以您只缺少一个字符:)
请参阅 Link calendar-v2-atom-oauth-示例。
完全披露:我是 google-api-java-client 项目的所有者。
The best documentation for the XML data model in the google-api-java-client library is the XML JavaDoc.
The @Key annotation to use with the name attribute is "@name". So you are only missing one character :)
See an example of the Link class in the calendar-v2-atom-oauth-sample.
Full disclosure: I'm an owner of the google-api-java-client project.