views:

95

answers:

2

Hi, I am looking for a C source snippet to validate XML string fromat. ex: Generalised source which checks for xml formatting. 10 must give an error for format. Thnx

A: 

Expat is a widely used XML parsing library written in C. I've used this in many different projects and it does its job well and it's fast.

Greg Hewgill
While expat is great, it's a non-validating parser. You can use it to check well-formedness (which may be what dusht wants, see my comment above), but if you really want to validate it's probably better to use a validating parser.
Laurence Gonsalves
That's a good point, I had automatically read between the lines and translated "formatting" to "well-formedness".
Greg Hewgill
A: 

If you don't want to include an external library, you can parse your xml with flex/bison (lex/yacc). An experimental code is available at the w3C: http://www.w3.org/XML/9707/XML-in-C

Pierre