105 {
106 XMLCh* xmlchEltName = XMLString::transcode(eltName);
107 XMLCh* xmlchName = XMLString::transcode("name");
108 XMLCh* xmlchValue = XMLString::transcode("value");
109 XMLCh* xmlchModified = XMLString::transcode("modified");
110 if (!doc) {
111 std::cerr << "invalid document " << std::endl;
112 return;
113 }
114
115
116 DOMNodeList* constList = doc->getElementsByTagName(xmlchEltName);
117 unsigned int nElt = constList->getLength();
118 for (unsigned int iElt = 0; iElt < nElt; iElt++) {
119 try {
120 bool mismatch = false;
121 DOMNode* item = constList->item(iElt);
122 DOMElement* itemElt = dynamic_cast<DOMElement *>(item);
123 DOMElement* byIdElt;
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) {
134 mismatch = true;
135 std::cout << "**** Address mismatch " << std::endl << std::endl;
136 }
137 XMLString::release(&namevalue);
138 }
139 std::cout << "Modifying value attribute using DOM_Element address" << std::endl;
140 itemElt->setAttribute(xmlchValue, xmlchModified);
141 if (mismatch) {
142 std::cout << "Modifying value attribute using looked-up address"
143 << std::endl;
144 byIdElt->setAttribute(xmlchValue, xmlchModified);
145
146 }
147 }
148 catch (DOMException ex) {
149 int code = ex.code;
150 std::cout << "***** Processing failed for element #" << iElt
151 << " with DOMException, code = "
152 << code << std::endl << std::endl;
153 }
154 }
155
156}