40int main(
int argc,
char* argv[] ) {
44 { infile = std::string(
"/u/ey/jrb/dev500/vanilla/xmlBase/v5r1/xml/simpleDoc.xml" ); }
45 else { infile = std::string( argv[1] ); }
48 { XMLPlatformUtils::Initialize(); }
catch (
const XMLException& toCatch )
50 char* charMsg = XMLString::transcode( toCatch.getMessage() );
51 std::string msg = std::string( charMsg );
52 XMLString::release( &charMsg );
54 std::cerr <<
"Error during Xerces-c Initialization.\n"
55 <<
" Exception message:" << msg << std::endl;
59 const char* inChars = infile.c_str();
60 XMLCh* xmlchPath = XMLString::transcode( inChars );
61 XercesDOMParser* parser =
new XercesDOMParser();
64 parser->setErrorHandler( errorHandler );
70 parser->setValidationScheme( AbstractDOMParser::Val_Auto );
72 std::cout <<
"create entity reference flag has default (true) value" << std::endl;
73 parser->parse( xmlchPath );
74 DOMDocument* doc = parser->getDocument();
75 std::cout <<
"Document successfully parsed" << std::endl;
76 std::cout <<
"processing local elements.. " << std::endl;
78 std::cout << std::endl <<
"processing external elements.. " << std::endl;
82 parser->setCreateEntityReferenceNodes(
false );
84 std::cout << std::endl
86 <<
"create entity reference flag has value false" << std::endl;
87 parser->parse( xmlchPath );
88 DOMDocument* expandDoc = parser->getDocument();
89 std::cout <<
"Document successfully parsed" << std::endl;
90 std::cout <<
"processing local elements.. " << std::endl;
92 std::cout <<
"processing external elements.. " << std::endl;
93 Process( expandDoc,
"extConst" );
96void Process( DOMDocument* doc,
char* eltName ) {
97 XMLCh* xmlchEltName = XMLString::transcode( eltName );
98 XMLCh* xmlchName = XMLString::transcode(
"name" );
99 XMLCh* xmlchValue = XMLString::transcode(
"value" );
100 XMLCh* xmlchModified = XMLString::transcode(
"modified" );
103 std::cerr <<
"invalid document " << std::endl;
108 DOMNodeList* constList = doc->getElementsByTagName( xmlchEltName );
109 unsigned int nElt = constList->getLength();
110 for (
unsigned int iElt = 0; iElt < nElt; iElt++ )
114 bool mismatch =
false;
115 DOMNode* item = constList->item( iElt );
116 DOMElement* itemElt =
dynamic_cast<DOMElement*
>( item );
118 std::cout << std::endl
119 << eltName <<
" #" << iElt <<
" Address as node: " << item
120 <<
" and as element: " << itemElt << std::endl;
121 const XMLCh* xmlchNamevalue = itemElt->getAttribute( xmlchName );
122 if ( XMLString::stringLen( xmlchNamevalue ) > 0 )
124 char* namevalue = XMLString::transcode( xmlchNamevalue );
125 std::cout <<
"element has name " << namevalue << std::endl;
126 byIdElt = doc->getElementById( xmlchNamevalue );
127 std::cout <<
"Address from getElementById: " << byIdElt << std::endl;
128 if ( byIdElt != itemElt )
131 std::cout <<
"**** Address mismatch " << std::endl << std::endl;
133 XMLString::release( &namevalue );
135 std::cout <<
"Modifying value attribute using DOM_Element address" << std::endl;
136 itemElt->setAttribute( xmlchValue, xmlchModified );
139 std::cout <<
"Modifying value attribute using looked-up address" << std::endl;
140 byIdElt->setAttribute( xmlchValue, xmlchModified );
142 }
catch ( DOMException ex )
145 std::cout <<
"***** Processing failed for element #" << iElt
146 <<
" with DOMException, code = " << code << std::endl
156 char* charSyst = XMLString::transcode( toCatch.getSystemId() );
157 std::string systemId( charSyst );
158 XMLString::release( &charSyst );
159 char* charMsg = XMLString::transcode( toCatch.getMessage() );
160 std::string msg( charMsg );
161 XMLString::release( &charMsg );
163 std::cerr <<
"Error at file \"" << systemId <<
"\", line " << toCatch.getLineNumber()
164 <<
", column " << toCatch.getColumnNumber() <<
"\n Message: " << msg <<
"\n\n";
170 char* charMsg = XMLString::transcode( toCatch.getMessage() );
171 std::string msg( charMsg );
172 XMLString::release( &charMsg );
174 if ( !( toCatch.getSystemId() ) )
176 std::cerr <<
"Fatal XML parse error: no such file "
177 <<
"\n Message: " << msg <<
"\n\n";
181 char* charSyst = XMLString::transcode( toCatch.getSystemId() );
182 std::string systemId( charSyst );
183 XMLString::release( &charSyst );
184 std::cerr <<
"Fatal error at file \"" << systemId <<
"\", line " << toCatch.getLineNumber()
185 <<
", column " << toCatch.getColumnNumber() <<
"\n Message: " << msg <<
"\n\n";