-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (44 loc) · 1.45 KB
/
main.cpp
File metadata and controls
52 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* \file main.cpp
* \brief XSD - XML Data Binding for C++
*
* \see https://codesynthesis.com/products/xsd/
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
#include <fstream>
#include <iostream>
#include "person.hxx"
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
try {
// Parse the XML file to create a person object
auto p = person::person_("person.xml");
if (p) {
// Display the parsed data
std::cout << "Name: " << p->name() << "\n";
std::cout << "Age: " << p->age() << "\n";
#if 0
// Serialize the person object to a file
std::ofstream ofs("output.xml");
if (!ofs) {
throw std::runtime_error("Failed to open output file.");
}
// Serialize the object to the file
person_(ofs, *p); // Generated function for serialization
std::cout << "Person object written to output.xml\n";
#endif
}
} catch (const xml_schema::exception& e) {
std::cerr << "XML schema error: " << e.what() << std::endl;
return 1;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------