2011-05-17 49 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