![]() |
![]()
| ![]() |
![]()
NAMExml2c - convert an XML file into C struct/string declarations SYNOPSISxml2c xmlfile DESCRIPTIONxml2c reads in an XML file and produces equivalent C source code, suitable for #including in your program. The C version is probably easier deal with in your code. You don't have to read and parse the XML file and then look for the nodes you want; instead you just loop through a bunch of structs. Or maybe you just don't want to distribute extra files with your app, and would rather build them into the executable. Example input: <?xml version="1.0" encoding="utf-8" ?> <list> Example output: % xml2c sample.xml struct _item { PROBLEMSxml2c should be able to produce output for any valid XML input file. However, there are some valid XML inputs for which the C output will not compile. For example, if there are XML elements with the same name but in different contexts, xml2c may not detect that they are the same and will produce two different struct definitions with the same name. That will result in a C compiler error, even if the two structs have the exact same fields: % cat bogus.xml <?xml version="1.0" encoding="utf-8" ?> <foo> Another case that can result in C compiler errors is if you use #include to bring multiple xml2c result files into a single .c file. If two or more of the XML files have elements with the same name, then the result files will have multiple struct definitions with the same name, and again that's a compiler error. AUTHORCopyright © 2011 by Jef Poskanzer <jef@mail.acme.com>. All rights reserved.
|