2017-11-14 7 views

답변

0

당신은 문서의 컨텍스트 내에서 요소를 만들고, 그래서

tinyxml2::XMLElement * tinyxml2::XMLDocument::NewElement (const char * name)를 호출합니다.

예. 새로운 요소를 생성하고 기존 요소 e

XMLElement * new = e -> GetDocument() -> NewElement ("tag"); 
e -> InsertFirstChild (new); 

또는 아이로 추가, 하나의 단계에서 그것을 할, 당신은 기존 응답과 유사

0

my tinyxml2 extensionappend_element을 볼 수 있었다, 내 응용 프로그램에 대한이 헬퍼 유틸리티를 작성했습니다 :

tinyxml2::XMLElement* CChristianLifeMinistryEntry::InsertNewElement(tinyxml2::XMLDocument& rDoc, tinyxml2::XMLElement*& pParent, LPCSTR strElement, CString strValue) 
{ 
    XMLElement *pElement = rDoc.NewElement(strElement); 

    USES_CONVERSION; 

    if (pElement == nullptr) 
     AfxThrowMemoryException(); 

    pElement->SetText(CT2CA(strValue, CP_UTF8)); 
    pParent->InsertEndChild(pElement); 

    return pElement; 
} 

자동으로 목록의 끝에 새 하위 요소를 추가합니다. 또한 요소의 텍스트 값을 설정합니다.