21 {
22 XERCES_CPP_NAMESPACE_USE
23
24 std::string infile;
25 if (argc < 2) {
26 infile=std::string("$(XMLBASEROOT)/xml/test.xml");
27 }
28 else {
29 infile = std::string(argv[1]);
30 }
31
33
35
36 DOMDocument* doc = 0;
37 try {
38 doc = parser->
parse(infile.c_str());
39 }
41 std::cout << "caught exception with message " << std::endl;
42 std::cout << ex.
getMsg() << std::endl;
43 delete parser;
44 return 0;
45 }
46
47 if (doc != 0) {
48 std::cout << "Document successfully parsed" << std::endl;
49
50
51 DOMElement* docElt = doc->getDocumentElement();
52 DOMElement* attElt =
54 double doubleVal;
55 int intVal;
56
57 try {
59 std::cout << "goodInt value was " << intVal << std::endl << std::endl;
60 }
62 std::cout << std::endl <<
"DomException: " << ex.
getMsg()
63 << std::endl << std::endl;
64 }
65
66 try {
67 std::vector<int> ints;
69 std::cout << "Found " << nInts << " goodInts: " << std::endl;
70 for (unsigned iInt=0; iInt < nInts; iInt++) {
71 std::cout << ints[iInt] << " ";
72 }
73 std::cout << std::endl << std::endl;
74 }
76 std::cout << std::endl << "DomException processing goodInts: "
77 << ex.
getMsg() << std::endl << std::endl;
78 }
79
80 try {
81 std::vector<double> doubles;
83 doubles);
84 std::cout << "Found " << nD << " goodDoubles: " << std::endl;
85 for (unsigned iD=0; iD < nD; iD++) {
86 std::cout << doubles[iD] << " ";
87 }
88 std::cout << std::endl << std::endl;
89 }
91 std::cout << std::endl << "DomException processing goodDoubles: "
92 << ex.
getMsg() << std::endl << std::endl;
93 }
94
95
96
97 try {
99 std::cout << "badInt value was " << intVal << std::endl << std::endl;
100 }
102 std::cout << std::endl <<
"DomException: " << ex.
getMsg()
103 << std::endl << std::endl;
104 }
105
106 try {
108 std::cout << "goodDouble value was " << doubleVal
109 << std::endl << std::endl;
110 }
112 std::cout << std::endl <<
"DomException: " << ex.
getMsg()
113 << std::endl << std::endl;
114 }
115
116 try {
118 std::cout << std::endl << "badDouble value was " << doubleVal
119 << std::endl << std::endl;
120 }
122 std::cout << std::endl <<
"DomException: " << ex.
getMsg()
123 << std::endl << std::endl;
124 }
125
126
127 try {
128 std::vector<double> doubles;
130 doubles);
131 std::cout << "Found " << nD << " badDoubles: " << std::endl;
132 for (unsigned iD=0; iD < nD; iD++) {
133 std::cout << doubles[iD] << " ";
134 }
135 std::cout << std::endl << std::endl;
136 }
138 std::cout << std::endl << "DomException processing badDoubles: "
140 << std::endl << std::endl;
141 }
142
143 if (argc > 2) {
144 char *hyphen = "-";
145
146 std::ostream* out;
147
148 if (*(argv[2]) == *hyphen) {
149 out = &std::cout;
150 }
151 else {
152 char *filename = argv[2];
153 out = new std::ofstream(filename);
154 }
155 *out << "Document source: " << std::string(argv[1]) << std::endl;
156 *out << std::endl << "Straight print of document:" << std::endl;
158 *out << std::endl << std::endl << "Add indentation and line breaks:"
159 << std::endl;
161 }
162 }
163 delete parser;
164 return(0);
165}
static int expandEnvVar(std::string *toExpand, const std::string &openDel=std::string("$("), const std::string &closeDel=std::string(")"))
Base exception class for Dom.
virtual std::string getMsg()
static int getIntAttribute(const DOMNode *elt, std::string attName)
static void prettyPrintElement(DOMNode *elt, std::ostream &out, std::string prefix)
static void printElement(DOMNode *elt, std::ostream &out)
static double getDoubleAttribute(const DOMNode *elt, std::string attName)
static DOMElement * findFirstChildByName(const DOMElement *parent, const char *const name)
static unsigned getDoublesAttribute(const DOMNode *elt, std::string attName, std::vector< double > &values, bool clear=true)
static unsigned getIntsAttribute(const DOMNode *elt, std::string attName, std::vector< int > &values, bool clear=true)
Exception class for XmlParser, XmlErrorHandler.
virtual std::string getMsg()
DOMDocument * parse(const char *const filename, const std::string &docType=std::string(""))
Parse an xml file, returning document node if successful.