2011-05-17 85 views
3

我想在spring项目中解析xml文件。任何人都可以为此提供方向吗?在Spring项目中读取和解析xml文件

此xml文件将用于加载需要验证每个jsf页面的各种字段。

我想使用该XML要通过文档生成工厂或任何通用函数存在于弹簧

DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 
Document doc = dBuilder.parse(fXmlFile); 

我想验证页,其在此xml定义的特定值读取。所以我需要解析这个XML文件,因为我们在简单的Java程序中使用DocumentBuilderFactory

+0

你想解析一个通用的XML文件,还是希望Spring读取你的XML配置文件并实例化你的bean? – MarcoS 2011-05-17 09:08:14

+0

你想解析任何.xml文件,或者你想解析spring配置xml文件? – Bozho 2011-05-17 09:08:46

+0

还是Java properties.xml文件? – 2011-05-17 09:10:07

回答

3

这个问题太模糊了,许多不同的场景都是可能的。

但是,我应该看看Spring参考的章节14. Marshalling XML using O/X Mappers。也许你会在那里找到答案。


啊,问题的更多信息。所以XML包含属性,尽管它不是Java属性的XML格式。

好的,那么我想我会write a BeanPostProcessor,使用Commons/Config下的引擎来读取XML的属性。您应该在某种程度上复制PropertyPlaceholderConfigurer的功能。

+0

我对AspectJ有新的问题(http:///stackoverflow.com/questions/6110948/using-aspectj-on-websphere) – Vish 2011-05-24 13:11:41