- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 xml 文件中有一个对象模型。该模型有根标签和其中的一些标签。我知道如何读取标签并将其解析为 POJO,但如何获取标签序列?
例如:
<citation type="default">
<part>first-author</part>
<part>title</part>
<part>type</part>
<part>authors-after</part>
<part>publisher</part>
<part>editors</part>
<part>publisher-city</part>
<part>publisher-name</part>
<part>year-date</part>
<part>volume</part>
<part>no</part>
<part>pages</part>
</citation>
我需要读取队列中的所有标签,这样我就可以按照与 xml 中相同的顺序一一读取它们。
最佳答案
来自文档:http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#list ,我给你举了一个例子。
我在这里采纳了这个想法:
读取元素列表
In XML configuration and in Java objects there is often a one to many relationship from a parent to a child object. In order to support this common relationship an ElementList annotation has been provided.
请注意,我不知道这个库,也没有测试过。如果结果不符合预期请告诉我。
引文类别:
@Root
public class Citation{
@ElementList
private List<Part> list;
@Attribute
private String type;
public String getType() {
return type;
}
public List<Part> getList() {
return list;
}
}
零件类别:
@Root
public class Part{
@Text
private String value;
public String getValue() {
return value;
}
}
反序列化您的文件:
Serializer serializer = new Persister();
File file = new File("yourXmlFile");
Citation citation = serializer.read(Citation.class, file);
关于java - SimpleXML 获取标签序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41206724/
这里发生了什么事? $string = XML; $xml = simplexml_load_string($string); // $xmlobj = sim
当我将 SimpleXML 解析为对象数组的一部分的字符串时,我一直坚持让 SimpleXML 返回一个对象。 $a = '1145869290false43false'; $resultA = si
我有两个 SimpleXML 对象。如何将一个对象添加为另一个对象的子元素。 请注意,这不能通过 addChild 方法完成,因为它会在添加之前将给定值转换为字符串。 最佳答案 我发现 SimpleX
http://pastie.org/1701923这是从我查询邮政编码的 API 返回的 XML。 我想从每个条目中提取数据,然后直接对其进行循环或将其放入我可以循环的数组中。我似乎无法正确处理。这是
这个问题在这里已经有了答案: remove xml version tag when a xml is created in php (10 个答案) 关闭 7 年前。 我使用 SimpleXML
与 DOM 或 Expat 解析器相比,SimpleXML 仅仅用几行代码就可以从 XML 元素中读取文本数据。 SimpleXML 可把 XML 文档(或 XML 字符串)转换为对象,比如:
我有一些看起来像这样的 XML: true 42 ;jsessionid=42 SimpleXML 以这种方式解析它: $obj
我有一个具有命名空间属性的 XML 文档。 XML 看起来像: 我如何提取 and
我想从元素id的属性创建一个数组,但是以下代码返回所有XML。 PHP文件: $xmlfile=simplexml_load_file("test.xml"); $test=$xmlfile->xpa
我有一个看起来像这样的XML结构: 0 Some survey question Answer 1 0 Answ
我正在尝试访问具有命名空间声明的节点中没有命名空间声明的节点列表。我的 XML 文件有一个带有命名空间 ehd 的主节点,在同一命名空间内有两个子节点 header、body。但是,主体节点内的所有子
我正在使用 SimpleXML 和 XPath 尝试获取子节点('IndexEntry)属性('indexKey')的值。节点的命名空间,我已在另一个节点(“记录”)上成功测试。由于某种原因,该节点的
我有两棵 XML 树,想将一棵树作为叶子添加到另一棵树上。 显然: $tree2->addChild('leaf', $tree1); 不起作用,因为它仅复制第一个根节点。 好吧,所以我想我应该遍历整
我正在使用 SimpleXML http://simple.sourceforge.net/home.php 在我的 Android 应用程序中, 我从 API 获取数据如下:
我想使用 SimpleXML 读取并解析包含员工信息的 XML 文件。框架。这是我的 XML 文件: 29 Pankaj
我正在尝试在 android 中使用 simplexml 解析此 xml 字符串: " " 是的,我知道门标签应该立即关闭,而不是在声明所有门标签后关闭,我无法控制这个
我有一个具有这种结构的 XML 文件:
请,我需要解析包含汽车信息的 XML 文件。我在汽车、照片中完成了所有操作,但我需要在额外的表中包含 id、汽车表 id 的外键,并且所有汽车都有随机的 Equipment_id。 我需要将其放入“设
我有一个看起来像这样的 xml: 在 xml 映射 java 代码中我有这样的东西: public class A { @Element(required=false)
我有一个xml文档如下: Calculations Description First Description Alan
我是一名优秀的程序员,十分优秀!