[英]How to parse XML by SAX and Create Tree list?
我已经学习了有关Java的SAX解析器的教程,现在我需要创建XML文件的树形列表,如下所示:
<course>
<chapter>
<title>chapter one of course one</title>
<content> .... </content>
</chapter>
<chapter>
<title>chapter two of course one</title>
<content> .... </content>
</chapter>
</course>
然后我要创建这样的数据结构:
string lessons[][] = {
{"chapter one of course one", "chapter two of course one"},
{"chapter one of course two", "chapter two of course two", "chapter tree of course two"},
....
....
}
这段代码完全可以满足您的需求,您只需对其进行调整即可输出所需的JSON结构。
您可以前往: 这是SAX文档,请阅读并尝试构建自己的解析器伴侣
考虑一个堆栈 。 在startElement()中按下,而在endElement中则弹出()。 根据元素标签的名称,您可以对堆栈中的内容以及“全局”上下文中的内容进行有趣的处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.