본문 바로가기
MFC

MSXML2 사용중 xmlns="" 자동 추가되는 문제 해결 방법

by leo21c 2016. 3. 7.
SMALL

MSXML2를 이용해서 XML을 처리하는데 문제가 발생해서 자료를 찾아보았다.
appendChild를 하면 xmlns=""이 자동으로 들어가는 문제였다.
MFC를 개발 경력 10년이 넘어서 처음으로 하는데 너무 불편한 것이 많다.
아래 글과 같이 XML Namespace를 처리하는 방식 때문인데 Dom의 namespace와 일치시켜면 자동으로 들어가지 않는다.
맨처음 DOM의 namespaceURI를 얻어와서 처리를 해 봤는데 NULL이 들어있다.
분면 XML에는 xmlns가 있는데도 말이다. 왜일까?
찾아봐야 할 것이 너무 많다.
직접 Root의 Attribute를 파싱해서 xmlns를 얻어오고 createNode를 이용해서 namespace를 직접 넣어주면 문제없이 잘 처리가 된다.
자신이 사용하는 XML의 xmlns를 잘 확인해 보길 바란다.

createElement는 name만 지정할 수 있다. 따라서 문제가 있으면 createNode를 사용해서 child를 만들어야 한다.


 How can I prevent appendChild() from adding the xmlns="" attribute?

The namespace of an element or attribute is determined when you create it thus you need to take care of namespaces when creating elements. With MSXML createElement is not namespace aware so if you use that you will always end up with elements in no namespace. To avoid that you need to use createNode e.g.

Set oNode = oXMLDOM.createNode(1, "PathAndCredentials", "urn:schemas-microsoft-com:asm.v3");

where 1 is the node type (element node), the second argument is the local name and the last argument is the namespace URI the node belongs to.




LIST