【发布时间】:2020-07-10 06:46:34
【问题描述】:
我正在尝试从此 graphml 创建节点和边缘对象。我有一些很好的建议,告诉我在进一步研究中使用多个包,它是我选择 simplexml 的 android 实现。
http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#nested
我从节点开始。我已经创建了我的节点类:
@Root(name="node")
public class DeserialisedNode implements Serializable {
public DeserialisedNode() {
super();
}
@Attribute(name = "id")
private int iD;
private String venueId;
@Element(name = "name")
private String name;
@Element(name = "waypoint_type")
private String type;
@Element(name = "lat")
private double latitude;
@Element(name = "lon")
private double longitude;
@Element(name = "level_id")
private int levelId;
@Element(name = "on_starting_route")
private String onStartingRoute;
@Element(name = "on_finish_route")
private String onFinishRoute;
public DeserialisedNode(int iD, String name, String type, double latitude, double longitude, int levelId, String onStartingRoute, String onFinishRoute) {
this.iD = iD;
this.name = name;
this.type = type;
this.latitude = latitude;
this.longitude = longitude;
this.levelId = levelId;
this.onStartingRoute = onStartingRoute;
this.onFinishRoute = onFinishRoute;
}
}
在我的 mainActivity 中我添加了:
try {
Serializer serializer = new Persister();
AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("routing.xml");
DeserialisedNode node = serializer.read(DeserialisedNode.class, inputStream);
System.out.println("It worked! "+node.getClass().getName());
System.out.println("It worked! "+node.getClass().getName());
}
catch (Exception e) {
e.printStackTrace();
System.out.println("error! "+e.getMessage());
}
xml开头的例子:
<?xml version='1.0' encoding='utf-8'?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key attr.name="weight" attr.type="double" for="edge" id="weight" />
<key attr.name="edgeid" attr.type="string" for="edge" id="edgeid" />
<key attr.name="alpha" attr.type="string" for="edge" id="alpha" />
<key attr.name="intendedpathlonlat" attr.type="string" for="edge" id="intendedpathlonlat" />
<key attr.name="levelid" attr.type="string" for="edge" id="levelid" />
<key attr.name="weight" attr.type="long" for="edge" id="weight" />
<key attr.name="type" attr.type="string" for="edge" id="type" />
<key attr.name="relatedroutes" attr.type="string" for="node" id="relatedroutes" />
<key attr.name="description" attr.type="string" for="node" id="description" />
<key attr.name="title" attr.type="string" for="node" id="title" />
<key attr.name="on_finish_route" attr.type="string" for="node" id="on_finish_route" />
<key attr.name="on_starting_route" attr.type="string" for="node" id="on_starting_route" />
<key attr.name="level_id" attr.type="string" for="node" id="level_id" />
<key attr.name="waypoint_type" attr.type="string" for="node" id="waypoint_type" />
<key attr.name="name" attr.type="string" for="node" id="name" />
<key attr.name="lon" attr.type="string" for="node" id="lon" />
<key attr.name="lat" attr.type="string" for="node" id="lat" />
<graph edgedefault="directed" id="new id here">
<node id="L08-022">
<data key="lat">30.69330963</data>
<data key="lon">-53.98752537</data>
<data key="name" />
<data key="waypoint_type">escalator</data>
<data key="level_id">1080000</data>
<data key="on_starting_route" />
<data key="on_finish_route" />
</node>
<node id="L08-023">
<data key="lat">30.69318355</data>
<data key="lon">-53.98755793</data>
<data key="name" />
<data key="waypoint_type">stairs</data>
<data key="level_id">1080000</data>
<data key="on_starting_route" />
<data key="on_finish_route" />
</node>
etc......
我的错误是:
W/System.err: org.simpleframework.xml.core.AttributeException: Attribute 'schemaLocation' does not have a match in class com.app.model.maps.DeserialisedNode at line 2
我需要取出节点和边缘数据。
【问题讨论】:
标签: java android xml xml-deserialization simple-framework