I have large data stored as XML files and I need to convert them to C++ by using the gnome-terminal in Ubuntu 14.04.
What is the best way to do that? Someone suggested to write a shell script to do that since we deal with large data.
I have large data stored as XML files and I need to convert them to C++ by using the gnome-terminal in Ubuntu 14.04.
What is the best way to do that? Someone suggested to write a shell script to do that since we deal with large data.
Your best method for reading an XML data file from a C++ program is to use an XML library. Search the internet for "C++ XML library".
Option 1 - leave the data in the XML files and read it out at run time. (recommended)
What you probably want to do is leave your XML files on disk, and then write a program to read those files in at runtime. Perhaps the filenames of those XML files can be passed as a command line to your program.
Then your program "reads" these XML files and parses them into a tree structure. There are a number of existing XML libraries that do all heavy parsing for you. One such library is libxml. Then your astrophysics code does its work to analyze your data.
Option 2 - "Use xxd -i" to convert XML into a C resource file.
If you absolutely want to convert XML to C++ code, then the best I can offer you is the xxd
command with the -i
option. That will turn a file into an array of unsigned chars in C code. Example:
ubuntu@ip-10-0-0-15:~$ cat foo.xml
<foo>
<data>This is some data</data>
</foo>
ubuntu@ip-10-0-0-15:~$ xxd -i foo.xml
unsigned char foo_xml[] = {0x3c, 0x66, 0x6f, 0x6f, 0x3e, 0x0a, 0x20, 0x20, 0x20, 0x3c, 0x64, 0x61, 0x74, 0x61, 0x3e, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x20, 0x64, 0x61, 0x74, 0x61, 0x3c, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x3e, 0x0a, 0x3c, 0x2f, 0x66, 0x6f, 0x6f, 0x3e, 0x0a};
unsigned int foo_xml_len = 47;
The unsigned char array, foo_xml
is an array of ascii bytes of the original file.
At runtime, you can convert that unsigned char array back into a string (don't forget to append a null char). Then use the XML library I mentioned above to parse the data.