[英]simplexml android Can't parse html with non-closing meta tag
I am trying to parse this xml string using simplexml in android: 我正在尝试使用android中的simplexml解析此xml字符串:
"<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
</head>
<body>
<doors>
<door id=\"1\" status=\"Closed\">
<door id=\"2\" status=\"Closed\">
<door id=\"3\" status=\"Closed\">
<door id=\"4\" status=\"Open\">
</door>
</door>
</door>
</door>
</doors>
</body>
</html>"
Yes, I know that the door tags should close immediately instead of after all the door tags have been declared, I have no control over this html!!! 是的,我知道门标签应该立即关闭,而不是在所有门标签都声明之后关闭,我无法控制此html !!!
I have a Doors class, and a Door class with attributes id and status. 我有一个Doors类和一个带有属性ID和Status的Door类。 (The Doors class has a List)
(“门”类有一个列表)
Anyway, what seems to be breaking is the parsing of the tag: 无论如何,似乎在中断的是标签的解析:
The Exception thrown is: 抛出的异常是:
expected: /meta read: head (position:END_TAG </head>@1:87 in java.io.StringReader@41ddc090)
I can see that it was expecting a closing meta tag, which doesn't exist. 我可以看到它正在期待一个不存在的结束元标记。 This tag is useless to me, how can I skip it?
这个标签对我没用,我如何跳过它? I just care about the door ids/statuses.
我只关心门的ID /状态。
Thanks 谢谢
Also, in case you care about the classes: 另外,如果您关心这些类:
Doors.java Doors.java
@Root(name="doors", strict=false)
public class Doors {
@ElementList(name="door")
private List<Door> doorList;
public Doors(){};
public List<Door> getDoors(){
return doorList;
}
public int getNumDoors(){
return doorList==null ? 0 : doorList.size();
}
}
Door.java Door.java
@Root(name="door")
public class Door {
@Attribute
private String id;
@Attribute
private String status;
public String getID(){
return id;
}
public String getStatus(){
return status;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.