void DOMNodeImpl::setTextContent(const XMLCh* textContent){ DOMNode *thisNode = castToNode(this); switch (thisNode->getNodeType()) { case DOMNode::ELEMENT_NODE: case DOMNode::ENTITY_NODE: case DOMNode::ENTITY_REFERENCE_NODE: case DOMNode::DOCUMENT_FRAGMENT_NODE: { if (isReadOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); // Remove all childs DOMNode* current = thisNode->getFirstChild(); while (current != NULL) { thisNode->removeChild(current); current = thisNode->getFirstChild(); } if (textContent != NULL) { // Add textnode containing data current = ((DOMDocumentImpl*)thisNode->getOwnerDocument())->createTextNode(textContent); thisNode->appendChild(current); } } break; case DOMNode::ATTRIBUTE_NODE: case DOMNode::TEXT_NODE: case DOMNode::CDATA_SECTION_NODE: case DOMNode::COMMENT_NODE: case DOMNode::PROCESSING_INSTRUCTION_NODE: if (isReadOnly()) throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager); thisNode->setNodeValue(textContent); break; case DOMNode::DOCUMENT_NODE: case DOMNode::DOCUMENT_TYPE_NODE: case DOMNode::NOTATION_NODE: break; default: throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager); } }
void CUtil::setNodeIntAttribute(DOMNode *node, unsigned short *attrName, int attr) { try { char buf[32]; sprintf(buf, "%d", attr); XMLCh xmlStr[100]; DOMNode *attrNode = node->getAttributes()->getNamedItem((XMLCh*)attrName); XMLString::transcode(buf, xmlStr, 99); attrNode->setNodeValue(xmlStr); } catch (...) { AfxMessageBox("Failed in setNodeIntAttribute"); } }
void XercesUpdateFactory::applyReplaceValue(const PendingUpdate &update, DynamicContext *context) { const XercesNodeImpl *nodeImpl = (const XercesNodeImpl*)update.getTarget()->getInterface(Item::gXQilla); DOMNode *domnode = const_cast<DOMNode*>(nodeImpl->getDOMNode()); // 2. If $target is a text, comment, or processing instruction node: content of $target is set to $string-value. domnode->setNodeValue(update.getValue().first()->asString(context)); if(domnode->getNodeType() == DOMNode::ATTRIBUTE_NODE) { // 1. If $target is an attribute node: // a. string-value of $target is set to $string-value. (done above) // b. upd:removeType($target) is invoked. removeType(domnode); } else if(domnode->getNodeType() == DOMNode::TEXT_NODE || domnode->getNodeType() == DOMNode::CDATA_SECTION_NODE) { // 3. If $target is a text node, upd:removeType(parent($target)) is invoked. if(domnode->getParentNode() != 0) removeType(domnode->getParentNode()); } addToPutSet(update.getTarget(), &update, context); }
void DSIGReference::setHash(void) { // First determine the hash value XMLByte calculatedHashVal[CRYPTO_MAX_HASH_SIZE]; // The hash that we determined unsigned int calculatedHashLen; XMLByte base64Hash [CRYPTO_MAX_HASH_SIZE * 2]; unsigned int base64HashLen; calculatedHashLen = calculateHash(calculatedHashVal, CRYPTO_MAX_HASH_SIZE); // Calculate the base64 value XSECCryptoBase64 * b64 = XSECPlatformUtils::g_cryptoProvider->base64(); if (!b64) { throw XSECException(XSECException::CryptoProviderError, "Error requesting Base64 object from Crypto Provider"); } Janitor<XSECCryptoBase64> j_b64(b64); b64->encodeInit(); base64HashLen = b64->encode(calculatedHashVal, calculatedHashLen, base64Hash, CRYPTO_MAX_HASH_SIZE * 2); base64HashLen += b64->encodeFinish(&base64Hash[base64HashLen], (CRYPTO_MAX_HASH_SIZE * 2) - base64HashLen); // Ensure the string is terminated if (base64Hash[base64HashLen-1] == '\n') base64Hash[base64HashLen-1] = '\0'; else base64Hash[base64HashLen] = '\0'; // Now find the correct text node to re-set DOMNode *tmpElt = mp_hashValueNode; if (mp_hashValueNode == 0) { throw XSECException(XSECException::NotLoaded, "setHash() called in DSIGReference before load()"); } tmpElt = mp_hashValueNode->getFirstChild(); while (tmpElt != NULL && tmpElt->getNodeType() != DOMNode::TEXT_NODE) tmpElt = tmpElt->getNextSibling(); if (tmpElt == NULL) { // Need to create the underlying TEXT_NODE DOMDocument *doc = mp_referenceNode->getOwnerDocument(); tmpElt = doc->createTextNode(MAKE_UNICODE_STRING((char *) base64Hash)); mp_hashValueNode->appendChild(tmpElt); } else { tmpElt->setNodeValue(MAKE_UNICODE_STRING((char *) base64Hash)); } }