验证具有基于树的结构的文件
我正在寻找一个验证器来验证基于树结构的配置文件。 egastudent.name 乔 a.student.class arts
您能否提出有关验证此类配置的任何想法。到目前为止,我已经搜索过,只能找到 xml 文件的验证器。
I am looking for a validator to validate tree structure based configuration files.
e.g.
a.student.name joe
a.student.class arts
Can you suggest any ideas on validating such config. So far I have searched and I could find validator for xml files only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果结构与 Java 属性文件相同,您可以从中读取属性。然后,您需要确定“验证”的含义。如果适用,您可能有一个简单的方法来解决您的问题。
If the structure is the same as a Java properties file, you can read properties from it. Then, you need to decide what you mean by "validate". If applicable, you probably have an easy way to solve your problem.
没有看到任何形式的样本。
如果你想验证某些东西的结构,并且语义不是问题,你可以使用 lex/yacc (阅读 flex/bison)。
根据问题的不同,人们可以在此之后冒险使用牛。基本上开始写一个迷你编译器了。
Without seeing any form of sample.
If you want to validate the structure of something, and semantics is not an issue you could use lex/yacc (read flex/bison).
Depending on the problem one could venture out and use ox after that. Basically starting to write a mini-compiler.
我发现自己有类似的需求,但找不到任何解决方案,所以我自己做了。
它是一个 Java 配置验证库,可以在这里找到: https://github.com/TTNO1/ConfigValidation4j
它可以进行定制,以适应您在配置中所需的确切规范,并且可以配置为与任何配置库一起使用,目前默认支持 Apache Commons Config 和 SnakeYAML。
I found myself with a similar need and could not find any solutions, so I made my own.
It's a configuration validation library for java and can be found here: https://github.com/TTNO1/ConfigValidation4j
It can be customized to suit the exact specifications that you need in your config and can be configured to work with any configuration library and currently comes with default support for Apache Commons Config and SnakeYAML.
不幸的是,配置文件的模式验证在 XML 之外很少见。我知道的唯一其他选项是 Config4J (我写的)。
如果您访问该网站,则应向下滚动到主页底部以访问完整的手册集(提供 PDF 和 HTML 版本)。我建议您查看手册的以下部分,以大致了解 Config4J 并确定它是否满足您的验证需求。
“入门指南”的第 2 章和第 3 章提供了配置语法和 API 的概述。特别是,第 3.10 节提供了模式语言的快速示例。
《入门指南》第 9 章提供了模式语言的完整定义。
《Java API 指南》的第 3 章讨论了用于编写自己的模式类型以扩展模式语言的功能的 API。
更新:我从 kiran.kumar M 的回答中发现 YAML< 的 Java 和 Ruby 实现/a> 有一个名为 Kwalify 的模式验证器。
更新:现在有一个JSON 架构语言。
Unfortunately, schema validation for configuration files is rare outside of XML. The only other option I am aware of is Config4J (which I wrote).
If you visit the website, then you should scroll down to the bottom of the main web page to access the complete set of manuals (available in both PDF and HTML versions). I recommend you have a look at the following parts of the manuals to get an overview of Config4J and decide if it satisfies your needs for validation.
Chapters 2 and 3 of the "Getting Started Guide" provide an overview of the configuration syntax and the API. In particular, Section 3.10 provides a quick example of the schema language.
Chapter 9 of the "Getting Started Guide" provides a complete definition of the schema language.
Chapter 3 of the "Java API Guide" discusses the API for writing your own schema types to extend the functionality of the schema language.
Update: I discovered from the answer by kiran.kumar M that the Java and Ruby implementations of YAML have a schema validator called Kwalify.
Update: There is now a schema language for JSON.
尝试 www.yaml.org 。 Yaml 支持树结构。
这是几个解析器的列表,
jYaml、SnakeYaml、YamlBeans
Yaml 是一种文件格式,支持复杂的层次结构。大多数结构验证可以由上面列出的解析器自动执行。您可能需要额外的代码来验证您的业务需求。
此外,还提供了一些在线验证器,
请参阅:
http://yaml-online-parser.appspot.com/
http://instantyaml.appspot.com/
另请参阅https://stackoverflow.com/questions/450399/which-java-yaml-库应该使用
验证https://stackoverflow.com/questions/287346/yaml-validation
Try www.yaml.org . Yaml supports tree structures.
Here is the list of few parsers,
jYaml, SnakeYaml , YamlBeans
Yaml is a file format and supports complex hirarchial structures. Most of the structural validations can be performed automatically by the parsers listed above. You may need addtional code to validate your business needs.
Also few online validators are also available
see :
http://yaml-online-parser.appspot.com/
http://instantyaml.appspot.com/
Also see https://stackoverflow.com/questions/450399/which-java-yaml-library-should-i-use
Validation https://stackoverflow.com/questions/287346/yaml-validation