Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: Re: Add JSON, XML, CSV to Baby X resource compiler Date: Sun, 19 May 2024 23:41:36 +0100 Organization: A noiseless patient Spider Lines: 46 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 20 May 2024 00:41:37 +0200 (CEST) Injection-Info: dont-email.me; posting-host="2cc898825537c031eb2f3a8ccd8931aa"; logging-data="3790906"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180sOaqCbX1U4yVfrZ0Z9bl" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:31cGzwwQh9sSrzGNgLAQ/zi+mds= In-Reply-To: Content-Language: en-GB Bytes: 3065 On 19/05/2024 11:16, Malcolm McLean wrote: > The Baby X resource compiler takes data - fonts, images, audio, strings > - and converts them into C source so that they can be read by C programs > without relying on external data files. > > An obvious extension is to take in structured data. Adding SQL and > querying a database would unfortuately mean extending the program so > that it could only run on a large machine with a SQL server running, and > isn't really a viable proposition. However JSON, XML, and CSV are > commonly used to pass small to medium amounts of data about. > > I've made a start on supporting CSV with the "" tag. CSV data > is tabular and two dimensional, and lends itself to an arrray of simple > structures. JSON And XML can of course represent more complex data, with > hierarchy. The dataframe tag is still very experimental. I've never used > it for anything practical. > > So what would be the best approach to putting in JSON and XML support? I've only briefly used XML. The problem with XML is that the data it represents is not just hierarchical, but it can be chaotic. You can have one lot of data, followed by another for something else with a different structure, followed by other. It is just a container for disparate sets of data. Even if the file does represent a simple list of records for example, you won't know that without reading it and analysing it. I looked online at an XML to CSV converter, which I thought would do something clever, but it seems to just turn each XML line into one string per line. Maybe it doesn't matter; the user of your program knows what's in their XML file, and will know what to do with the different bits. It's their problem. But you still have to figure out how to represent an arbitary data structure as C data. Plus you have to deal with tag names, and attributes. Personally, I would suggest using converters (ones clever than the CSV one I tried) to turn XML files into better-organised formats first.