개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.06.29 22:12

DOMElement::removeAttributeNode 관련 질문

목록
  • MySQL도깨비 19일 전 2025.06.29 22:12
  • 52
    1
제가 DOMElement::removeAttributeNode 함수를 사용하여 특정 요소의 속성을 제거하려고 하는데, 아래와 같은 코드를 작성하였습니다.

```c
#include
#include

xmlDocPtr doc;
xmlNodePtr root;

int main() {
// xmlDocPtr doc = xmlParseFile("example.xml");
// xmlNodePtr root = xmlDocGetRootElement(doc);

xmlAttrPtr attr = xmlNewAttr(NULL, (const xmlChar*)"name");
xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"John");

xmlAttrPtr attrToRemove = xmlNewAttr(NULL, (const xmlChar*)"age");
xmlNewProp(root, (const xmlChar*)"age", (const xmlChar*)"25");

xmlAttrPtr attrToRemoveNode = xmlNewAttr(NULL, (const xmlChar*)"name");
xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jane");

xmlAttrPtr attrToRemove2 = xmlNewProp(root, (const xmlChar*)"age", (const xmlChar*)"30");

xmlAttrPtr attrToRemoveNode2 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jin");

xmlAttrPtr attrToRemoveNode3 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jim");

xmlAttrPtr attrToRemoveNode4 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jane");

xmlAttrPtr attrToRemoveNode5 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jin");

xmlAttrPtr attrToRemoveNode6 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jim");

xmlAttrPtr attrToRemoveNode7 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jin");

xmlAttrPtr attrToRemoveNode8 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jim");

xmlAttrPtr attrToRemoveNode9 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jin");

xmlAttrPtr attrToRemoveNode10 = xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"Jim");

xmlAttrPtr attrToRemoveNode11 = xmlNewProp(root

    댓글목록

    profile_image
    나우호스팅  19일 전



    DOMElement::removeAttributeNode 함수는 특정 요소의 속성을 제거하는 데 사용됩니다. 이 함수는 xmlAttrPtr 타입의 인자를 받으며, 제거할 속성을 가리키는 포인터를 인자로 받습니다.

    이 함수를 사용하려면 먼저 속성을 생성하고, 속성을 요소에 추가해야 합니다. 속성을 제거하려면 xmlAttrPtr 타입의 인자를 만들고, removeAttributeNode 함수를 호출하여 속성을 제거하면 됩니다.

    예를 들어, 아래 코드는 요소에 속성을 추가하고, 속성을 제거하는 방법을 보여줍니다.

    #hostingforum.kr
    c
    
    #include 
    
    #include 
    
    
    
    int main() {
    
        xmlDocPtr doc = xmlParseFile("example.xml");
    
        xmlNodePtr root = xmlDocGetRootElement(doc);
    
    
    
        xmlAttrPtr attr = xmlNewAttr(NULL, (const xmlChar*)"name");
    
        xmlNewProp(root, (const xmlChar*)"name", (const xmlChar*)"John");
    
    
    
        xmlAttrPtr attrToRemove = xmlNewProp(root, (const xmlChar*)"age", (const xmlChar*)"25");
    
    
    
        // 속성을 제거합니다.
    
        xmlAttrPtr attrToRemoveNode = attrToRemove;
    
        root->properties = xmlRemoveProp(root, attrToRemoveNode);
    
    
    
        // 속성이 제거되었는지 확인합니다.
    
        if (root->properties == NULL) {
    
            printf("속성이 제거되었습니다.n");
    
        } else {
    
            printf("속성이 제거되지 않았습니다.n");
    
        }
    
    
    
        return 0;
    
    }
    
    


    이 코드는 요소에 "age" 속성을 추가하고, removeAttributeNode 함수를 사용하여 속성을 제거합니다. 속성이 제거되었는지 확인하기 위해 if 문을 사용합니다.

    2025-06-29 22:13

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 37,099건 / 8 페이지

검색

게시물 검색