Ecere SDK/eC Forums http://ecere.com/community/ Print view |
|
Example on reading/writing xml file? http://ecere.com/community/viewtopic.php?f=1&t=208 |
Page 1 of 1 |
Author: | samsam598 [ Thu Jan 12, 2012 7:20 pm ] |
Post subject: | Example on reading/writing xml file? |
Greetings, Is there any example code that reading from a xml file to the console and writing back? Thanks for the help in advance. Regards, Sam |
Author: | jerome [ Sat Jan 14, 2012 11:03 pm ] |
Post subject: | Re: Example on reading/writing xml file? |
Hi Sam! Sorry for the late replies... About XML, the only thing we have in the SDK is under sdk/extras/XMLParser. It is a very simple XML parser. To use it, you basically derive a class from the XMLParser class, and override its two methods. Then you instantiate your derived class and invoke the Parse method with a string containing the XML text data to parse and its length. The two methods to override are:
Code: Select all
Alternatively, libexpat is a decent open source C library for dealing with XML files, which you should be able to use in conjunction with Ecere/eC without too much trouble Additionally, Ecere provides a class to parse and save JSON (Java Script Object Notation) data. I personally prefer by far JSON over XML, and JSON is what is used for the new Ecere project file format (.epj). It is also used by the newest IDE configuration settings and is an option for the GlobalAppSettings class. The JSON parser is used by defining a class which essentially describes the schema of the data. The class can contain eC containers (specifying the elements data type, e.g. Array<int>) to organize the hierarchy of the data. Then the parser will automatically store the data being parsed in an instance of such a class, and can write back the data from the instance. This sounds a bit like what you are trying to do, right? It would be possible (and interesting) to make this work with XML as well, maybe with some code from the JSONParser class on top of the XMLParser. But I still prefer JSON as the data format is more compact and readable Hope this helps Please let me know if you have further questions about these tools. Best regards, Jerome |
Author: | jerome [ Sun Jan 15, 2012 12:43 am ] |
Post subject: | Re: Example on reading/writing xml file? |
Added Note: you might find useful to keep flag(s) saying whether you're inside a particular tag (you set the flag in ProcessKeyword). Then you can check this flag within ProcessCharacterData, and you only care about the data for tags actually meant to contain character data (higher level tags container other tags usually don't)... Some types of XML files might describe everything as tags and do not use character data at all... JSON doesn't suffer from this confusion... Everything is a very specific data type, no character data unless you are within an attribute! Take a look at http://www.json.org/xml.html XML is awful, truly! |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |