Spring项目中读取并解析xml文件
我想在spring项目中解析xml文件。有人可以为此提供指导吗?
该 xml 文件将用于加载每个 jsf 页面需要验证的各种字段。
我想使用此 xml 通过文档构建工厂或 spring 中存在的任何通用函数来读取
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
我想验证页面中在此 xml 中定义的特定值。所以我需要像我们在简单的java程序中使用DocumentBuilderFactory
一样解析这个xml文件
I want to parse xml file in spring project. Can anyone provide direction for this?
This xml file will be used to load various fields which are required to be validated for each jsf page.
I want to use this xml to be read through document build factory or any generic function present in the spring
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
I want to validate a page for specific values which are defined in this xml. So I need to parse this xml file as we do in simple java program using DocumentBuilderFactory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题太模糊了,可能有很多不同的情况。
但是,我认为您应该看一下章节 14。使用 Spring 参考中的 O/X 映射器编组 XML。也许你会在那里找到答案。
啊,问题中的更多信息。因此,XML 包含属性,尽管它不是 Java 属性 XML 格式。
好的,那么我想我会 编写一个 BeanPostProcessor,它在底层使用 Commons / Config 来读取的属性来自XML。您可能应该复制 PropertyPlaceholderConfigurer 在某种程度上确实如此。
The question is much too vague, many different scenarios are possible.
However, I thing you should take a look at the Chapter 14. Marshalling XML using O/X Mappers from the Spring reference. Perhaps you will find the answer there.
Ah, more info in the Question. So the XML contains properties, although it is not in the Java properties XML format.
OK, then I guess I'd write a BeanPostProcessor that uses Commons / Config under the hood to read the properties from XML. You should probably copy what the PropertyPlaceholderConfigurer does, to a certain extent.