42int main(
int argc,
char* argv[]) {
46 infile=std::string(
"/u/ey/jrb/dev500/vanilla/xmlBase/v5r1/xml/simpleDoc.xml");
49 infile = std::string(argv[1]);
53 XMLPlatformUtils::Initialize();
55 catch(
const XMLException& toCatch)
57 char* charMsg = XMLString::transcode(toCatch.getMessage());
58 std::string msg = std::string(charMsg);
59 XMLString::release(&charMsg);
61 std::cerr <<
"Error during Xerces-c Initialization.\n"
62 <<
" Exception message:" << msg << std::endl;
66 const char* inChars = infile.c_str();
67 XMLCh* xmlchPath = XMLString::transcode(inChars);
68 XercesDOMParser* parser =
new XercesDOMParser();
71 parser->setErrorHandler(errorHandler);
77 parser->setValidationScheme(AbstractDOMParser::Val_Auto);
80 std::cout <<
"create entity reference flag has default (true) value" <<
82 parser->parse(xmlchPath);
83 DOMDocument* doc = parser->getDocument();
84 std::cout <<
"Document successfully parsed" << std::endl;
85 std::cout <<
"processing local elements.. " << std::endl;
87 std::cout << std::endl <<
"processing external elements.. " << std::endl;
91 parser->setCreateEntityReferenceNodes(
false);
93 std::cout << std::endl << std::endl \
94 <<
"create entity reference flag has value false" << std::endl;
95 parser->parse(xmlchPath);
96 DOMDocument* expandDoc = parser->getDocument();
97 std::cout <<
"Document successfully parsed" << std::endl;
98 std::cout <<
"processing local elements.. " << std::endl;
100 std::cout <<
"processing external elements.. " << std::endl;
101 Process(expandDoc,
"extConst");
105void Process(DOMDocument* doc,
char* eltName) {
106 XMLCh* xmlchEltName = XMLString::transcode(eltName);
107 XMLCh* xmlchName = XMLString::transcode(
"name");
108 XMLCh* xmlchValue = XMLString::transcode(
"value");
109 XMLCh* xmlchModified = XMLString::transcode(
"modified");
111 std::cerr <<
"invalid document " << std::endl;
116 DOMNodeList* constList = doc->getElementsByTagName(xmlchEltName);
117 unsigned int nElt = constList->getLength();
118 for (
unsigned int iElt = 0; iElt < nElt; iElt++) {
120 bool mismatch =
false;
121 DOMNode* item = constList->item(iElt);
122 DOMElement* itemElt =
dynamic_cast<DOMElement *
>(item);
124 std::cout << std::endl << eltName <<
" #" << iElt
125 <<
" Address as node: "
126 << item <<
" and as element: " << itemElt << std::endl;
127 const XMLCh* xmlchNamevalue = itemElt->getAttribute(xmlchName);
128 if (XMLString::stringLen(xmlchNamevalue) > 0 ) {
129 char* namevalue = XMLString::transcode(xmlchNamevalue);
130 std::cout <<
"element has name " << namevalue << std::endl;
131 byIdElt = doc->getElementById(xmlchNamevalue);
132 std::cout <<
"Address from getElementById: " << byIdElt << std::endl;
133 if (byIdElt != itemElt) {
135 std::cout <<
"**** Address mismatch " << std::endl << std::endl;
137 XMLString::release(&namevalue);
139 std::cout <<
"Modifying value attribute using DOM_Element address" << std::endl;
140 itemElt->setAttribute(xmlchValue, xmlchModified);
142 std::cout <<
"Modifying value attribute using looked-up address"
144 byIdElt->setAttribute(xmlchValue, xmlchModified);
148 catch (DOMException ex) {
150 std::cout <<
"***** Processing failed for element #" << iElt
151 <<
" with DOMException, code = "
152 << code << std::endl << std::endl;
167 char* charSyst = XMLString::transcode(toCatch.getSystemId());
168 std::string systemId(charSyst);
169 XMLString::release(&charSyst);
170 char* charMsg = XMLString::transcode(toCatch.getMessage());
171 std::string msg(charMsg);
172 XMLString::release(&charMsg);
174 std::cerr <<
"Error at file \"" << systemId
175 <<
"\", line " << toCatch.getLineNumber()
176 <<
", column " << toCatch.getColumnNumber()
177 <<
"\n Message: " << msg <<
"\n\n";
183 char* charMsg = XMLString::transcode(toCatch.getMessage());
184 std::string msg(charMsg);
185 XMLString::release(&charMsg);
187 if (!(toCatch.getSystemId()) ) {
188 std::cerr <<
"Fatal XML parse error: no such file "
189 <<
"\n Message: " << msg <<
"\n\n";
192 char* charSyst = XMLString::transcode(toCatch.getSystemId());
193 std::string systemId(charSyst);
194 XMLString::release(&charSyst);
195 std::cerr <<
"Fatal error at file \""
197 <<
"\", line " << toCatch.getLineNumber()
198 <<
", column " << toCatch.getColumnNumber()
199 <<
"\n Message: " << msg <<
"\n\n";