//====================================================================== //====================================================================== bool XMLDocument::doAttributesMatch(DOM_Node currNode, DataTypeAttribute** dtAttributes) { DOM_NamedNodeMap nnodeMap = currNode.getAttributes(); int len = nnodeMap.getLength(); int a = 0; DataTypeAttribute* dtAttribute; while ((dtAttribute = (DataTypeAttribute*)dtAttributes[a++]) != (DataTypeAttribute*)NULL) { bool isFound = false; for (int i = 0; i < len && !isFound; i++) { DOM_Node attNode = nnodeMap.item(i); char* tmp = attNode.getNodeName().transcode(); char* tmp1 = attNode.getNodeValue().transcode(); if (strcmp(dtAttribute->getName(), tmp) == 0 && strcmp(dtAttribute->getValue(), tmp1) == 0) { isFound = true; } delete[] tmp; delete[] tmp1; } if (!isFound) return false; } return true; }
//====================================================================== // CJM 4/17/03 ..Needed to update an attribute list... for ContentGuard //====================================================================== bool XMLDocument::setAttributeList(char* path, DataTypeAttribute** dtAttributes) { if (mDoc == NULL) return false; if (path == NULL) return false; DOM_Node child = getNode(mRootNode, path, NULL); char* value = getString(path); if (child == NULL) return false; short nType = child.getNodeType(); DOM_Node parent = child.getParentNode(); if (parent == NULL) return false; char* childName = child.getNodeName().transcode(); DOM_NamedNodeMap nnodeMap = child.getAttributes(); parent.removeChild(child); DOM_Element childElement = mDoc.createElement(childName); delete[] childName; int a = 0; DataTypeAttribute* dtAttribute; while ((dtAttribute = (DataTypeAttribute*)dtAttributes[a++]) != (DataTypeAttribute*)NULL) { childElement.setAttribute(dtAttribute->getName(), dtAttribute->getValue()); } if (nType == DOM_Node::TEXT_NODE) { DOM_Text childText = mDoc.createTextNode((value == NULL)?"":value); childElement.appendChild(childText); } else { if (nType == DOM_Node::CDATA_SECTION_NODE) { DOM_CDATASection childCData = mDoc.createCDATASection((value == NULL)?"":value); childElement.appendChild(childCData); } } parent.appendChild(childElement); return true; }
//====================================================================== //====================================================================== bool XMLDocument::setValue(DOM_Node currNode, char* path, DataTypeAttribute** dtAttributes, char* value) { if (mDoc == NULL) return false; if (path == NULL) return false; DOM_Node child = getNode(currNode, path, dtAttributes); if (child == NULL) return false; DOM_Node parent = child.getParentNode(); if (parent == NULL) return false; DOM_Node grandChild = child.getFirstChild(); short nType = DOM_Node::TEXT_NODE; if (grandChild != NULL) { nType = grandChild.getNodeType(); if (nType != DOM_Node::TEXT_NODE && nType != DOM_Node::CDATA_SECTION_NODE) return false; } char* childName = child.getNodeName().transcode(); DOM_NamedNodeMap nnodeMap = child.getAttributes(); parent.removeChild(child); DOM_Element childElement = mDoc.createElement(childName); delete[] childName; for (unsigned int i = 0; i < nnodeMap.getLength(); i++) { DOM_Node attNode = nnodeMap.item(i); childElement.setAttribute(attNode.getNodeName(), attNode.getNodeValue()); } if (nType == DOM_Node::TEXT_NODE) { DOM_Text childText = mDoc.createTextNode((value == NULL)?"":value); childElement.appendChild(childText); } else { DOM_CDATASection childCData = mDoc.createCDATASection((value == NULL)?"":value); childElement.appendChild(childCData); } parent.appendChild(childElement); return true; }
DOM_Node XMLDocument::clone(DOM_Node currNode) { switch (currNode.getNodeType()) { case DOM_Node::ELEMENT_NODE: { DOM_Element elem = mDoc.createElement(currNode.getNodeName()); DOM_NamedNodeMap nnodeMap = currNode.getAttributes(); for (unsigned int i = 0; i < nnodeMap.getLength(); i++) { DOM_Node attNode = nnodeMap.item(i); elem.setAttribute(attNode.getNodeName(), attNode.getNodeValue()); } DOM_Node child = currNode.getFirstChild(); while (child != NULL) { DOM_Node cNode = clone(child); if (cNode != NULL) elem.appendChild(cNode); child = child.getNextSibling(); } return (DOM_Node)elem; } case DOM_Node::TEXT_NODE: { DOM_Text childText = mDoc.createTextNode(currNode.getNodeValue()); return (DOM_Node)childText; } case DOM_Node::CDATA_SECTION_NODE: { DOM_CDATASection childCData = mDoc.createCDATASection(currNode.getNodeValue()); return (DOM_Node)childCData; } default: { return NULL_DOM_Node; } } }