如何使用公共配置java读取复杂的xml
我需要使用公共配置读取复杂的XML文件。有人能帮我吗如何使用公共配置java读取复杂的xml,java,xml,apache-commons-config,Java,Xml,Apache Commons Config,我需要使用公共配置读取复杂的XML文件。有人能帮我吗 <configurations> <configuration type="application configuration"> <group id="1" name="President"> <sentiment-searcher> <sentiment id="1" type="sentiment candidate 1
<configurations>
<configuration type="application configuration">
<group id="1" name="President">
<sentiment-searcher>
<sentiment id="1" type="sentiment candidate 1">
<positive>'Obama okay' 'Obama great'</positive>
<negative>'Obama bad' 'Obama idiot'</negative>
</sentiment>
<sentiment id="2" type="sentiment candidate 2">
<positive>'Putin okay'</positive>
<negative>'Putin bad'</negative>
</sentiment>
</sentiment-searcher>
</group>
</configuration>
</configurations>
“奥巴马很好”“奥巴马很好”
“奥巴马坏了”“奥巴马白痴”
“普京好吧”
“普京坏了”
可能不是执行此任务的合适工具。当您已经知道密钥名称时(即,当您知道您想要获得some.important.config
),配置API很有用,但当您不知道元素的外观和密钥可能是什么时,它不太适合处理复杂的嵌套数据结构
STaX API更适合此任务
如果仍要使用commons配置,文档将解释如何以及如何使用。您可以:
使用xml解析器
DOM
为方便起见,SAX/STAX
为超大文件。除非您面临任何特定问题,否则您需要的是使用通用配置(apache)的标准配置。检查是的,这是标准的,对不起,先生,我是新手:)