21 {
22 XERCES_CPP_NAMESPACE_USE
23
24 std::string infile;
25 if ( argc < 2 ) { infile = std::string( "$(XMLBASEROOT)/xml/test.xml" ); }
26 else { infile = std::string( argv[1] ); }
27
29
31
32 DOMDocument* doc = 0;
33 try
35 {
36 std::cout << "caught exception with message " << std::endl;
37 std::cout << ex.
getMsg() << std::endl;
38 delete parser;
39 return 0;
40 }
41
42 if ( doc != 0 )
43 {
44 std::cout << "Document successfully parsed" << std::endl;
45
46
47 DOMElement* docElt = doc->getDocumentElement();
49 double doubleVal;
50 int intVal;
51
52 try
53 {
55 std::cout << "goodInt value was " << intVal << std::endl << std::endl;
57 { std::cout << std::endl <<
"DomException: " << ex.
getMsg() << std::endl << std::endl; }
58
59 try
60 {
61 std::vector<int> ints;
63 std::cout << "Found " << nInts << " goodInts: " << std::endl;
64 for ( unsigned iInt = 0; iInt < nInts; iInt++ ) { std::cout << ints[iInt] << " "; }
65 std::cout << std::endl << std::endl;
67 {
68 std::cout << std::endl
69 <<
"DomException processing goodInts: " << ex.
getMsg() << std::endl
70 << std::endl;
71 }
72
73 try
74 {
75 std::vector<double> doubles;
77 std::cout << "Found " << nD << " goodDoubles: " << std::endl;
78 for ( unsigned iD = 0; iD < nD; iD++ ) { std::cout << doubles[iD] << " "; }
79 std::cout << std::endl << std::endl;
81 {
82 std::cout << std::endl
83 <<
"DomException processing goodDoubles: " << ex.
getMsg() << std::endl
84 << std::endl;
85 }
86
87 try
88 {
90 std::cout << "badInt value was " << intVal << std::endl << std::endl;
92 { std::cout << std::endl <<
"DomException: " << ex.
getMsg() << std::endl << std::endl; }
93
94 try
95 {
97 std::cout << "goodDouble value was " << doubleVal << std::endl << std::endl;
99 { std::cout << std::endl <<
"DomException: " << ex.
getMsg() << std::endl << std::endl; }
100
101 try
102 {
104 std::cout << std::endl << "badDouble value was " << doubleVal << std::endl << std::endl;
106 { std::cout << std::endl <<
"DomException: " << ex.
getMsg() << std::endl << std::endl; }
107
108 try
109 {
110 std::vector<double> doubles;
112 std::cout << "Found " << nD << " badDoubles: " << std::endl;
113 for ( unsigned iD = 0; iD < nD; iD++ ) { std::cout << doubles[iD] << " "; }
114 std::cout << std::endl << std::endl;
116 {
117 std::cout << std::endl
118 <<
"DomException processing badDoubles: " << ex.
getMsg() << std::endl
119 << std::endl;
120 }
121
122 if ( argc > 2 )
123 {
124 char* hyphen = "-";
125
126 std::ostream* out;
127
128 if ( *( argv[2] ) == *hyphen ) { out = &std::cout; }
129 else
130 {
131 char* filename = argv[2];
132 out = new std::ofstream( filename );
133 }
134 *out << "Document source: " << std::string( argv[1] ) << std::endl;
135 *out << std::endl << "Straight print of document:" << std::endl;
137 *out << std::endl << std::endl << "Add indentation and line breaks:" << std::endl;
139 }
140 }
141 delete parser;
142 return ( 0 );
143}
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.