3

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.

MoveFast
  • 3,011
  • 2
  • 27
  • 53
  • can you give some sample validations that you need to perform? Or are you thinking of a schema specification for property files? – rahulmohan May 25 '11 at 18:01
  • @rahulmohan: I am not the OP, but I am the person who is offering the bounty. I am interesting to hearing about ANY tools or libraries for performing schema validation on non-XML configuration files. As I stated in my answer, my Config4J library is the only schema-validating configuration-file parser I am aware of outside of XML. I'm hoping to learn of other ones too. – Ciaran McHale May 26 '11 at 12:37
  • Do you want to check against the keys or the values? Or just the wellformedness? – Wolfgang May 28 '11 at 17:58
  • @Wolfgang: by "schema validation" I do not mean syntax checking (what you call wellformedness). I mean being able to do some semantic checks. For example, if a line in the config file is of the form _name=value_, then a schema validator should be able to check that _value_ is, for example, an integer in the range 0..10, or one of a specific set of strings, such as "red", "green" or "blue". It should be possible for the user to _declare_ (rather than have to code) such validation constraints. XML and Config4J provide such schema validation mechanisms. – Ciaran McHale May 29 '11 at 10:24

4 Answers4

8

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.

Ciaran McHale
  • 2,126
  • 14
  • 21
1

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

Community
  • 1
  • 1
kiran.kumar M
  • 811
  • 8
  • 25
  • I was aware of YAML, but thought it didn't provide support for schema validation. However, having had a look at some of the links you provide, I found Kwalify, which is a Java and Ruby library for performing schema validation of YAML files. Unless somebody else can point out something better, you'll probably get the bounty. – Ciaran McHale May 29 '11 at 10:32
0

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.

ymajoros
  • 2,454
  • 3
  • 34
  • 60
0

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.

Eduard Thamm
  • 942
  • 1
  • 6
  • 7