コード例 #1
0
XMLNodePtr XMLDoc::createNode(const XMLNodePtr &parent, const TCHAR *nodeName, bool force) {
  DEFINEMETHODNAME;
  if(parent == NULL) {
    throwInvalidArgumentException(method, _T("parent=NULL"));
  }
  if(nodeName == NULL || _tcsclen(nodeName) == 0) {
    throwInvalidArgumentException(method, _T("nodeName=%s"), nodeName?nodeName:_T("null"));
  }

  StringArray tokens(Tokenizer(nodeName,_T(".")));

  // Create path if we got any dots
  XMLNodePtr node = parent;
  size_t i;
  for(i = 0; i < tokens.size() - 1; i++) {
    XMLNodePtr tmp = findChild(node,tokens[i].cstr());
    if(tmp == NULL) {
      tmp  = m_doc->createElement(tokens[i].cstr());
      node = node->appendChild(tmp);
    }
  }

  XMLNodePtr result = findChild(node,tokens[i].cstr());
  if(result != NULL && !force) {
    throwException(_T("Node %s alredy exist. set force to true, if duplicates are allowed"), nodeName);
  } else {
    result = m_doc->createElement(tokens[i].cstr());
    result = node->appendChild(result);
  }
  return result;
}
コード例 #2
0
void XMLDoc::setText(const XMLNodePtr &node, const TCHAR *value) {
  if(node == NULL) {
    return;
  }
  XMLNodePtr Text = findText(node);
  if(Text == NULL) {
    node->appendChild(m_doc->createTextNode(value));
  } else {
    Text->nodeValue = value;
  }
}