Validating files having tree based structures
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 sug开发者_运维问答gest any ideas on validating such config. So far I have searched and I could find validator for xml files only.
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.
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
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.
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.
精彩评论