MSXML에서 createElement를 사용할 때 자동으로 xmlns="" 속성이 붙는 이유는 네임스페이스를 지정하지 않고 요소를 생성했기 때문입니다. 이를 막으려면 createElement 대신 createNode를 사용하여 네임스페이스를 명시적으로 지정하거나, createElement 호출 시 올바른 네임스페이스를 함께 전달해야 합니다.
how to remove the xmlns attribute that gets added by the xmldocument - Microsoft Q&A
Hi experts , i have a scenario, where i have to read the xml document and create/add an xmlnode to the document. newElem = xmlDocument.CreateNode("element", "newnode", ""); //creates the node newElem.InnerText…
learn.microsoft.com
1. createNode 사용하기
MFC에서 COM 인터페이스를 직접 호출하면 됩니다.
#import <msxml6.dll> named_guids
MSXML2::IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
// 루트 생성
MSXML2::IXMLDOMElementPtr pRoot = pDoc->createElement(L"root");
pDoc->appendChild(pRoot);
// 네임스페이스 없는 노드 생성
MSXML2::IXMLDOMNodePtr pNode = pDoc->createNode(
MSXML2::NODE_ELEMENT, // 노드 타입
L"child", // 이름
L"" // 네임스페이스 URI (빈 문자열)
);
pNode->text = L"Hello";
pRoot->appendChild(pNode);
2. createElement 대신 네임스페이스 지정
MSXML2::IXMLDOMElementPtr pElem = pDoc->createElement(L"ns:child");
pElem->setAttribute(L"xmlns:ns", L"http://example.com/ns");
pRoot->appendChild(pElem);
3. 이미 붙은 xmlns="" 제거
pElem->removeAttribute(L"xmlns");
정리
- MFC에서 MSXML 사용 시 createElement만 쓰면 xmlns=""가 자동 추가됨.
- 해결책은
- createNode(NODE_ELEMENT, name, "") 사용
- createElement 호출 시 네임스페이스 지정
- 필요 시 removeAttribute("xmlns")로 제거
LIST
'MFC' 카테고리의 다른 글
| BluetoothFindFirstDevice Example (0) | 2024.10.21 |
|---|---|
| CFileDialog의 Title 이름 변경하는 방법 (0) | 2024.01.16 |
| MFC 단축키 Accelerator 리소스 추가 (0) | 2024.01.16 |
| 최근 열어본 파일 MRU Menu Items 처리 커스텀 방법 (1) | 2024.01.15 |
| UpdateData() 함수 Param 의미 (0) | 2023.07.07 |