
XMLDiffBase::diff 함수에서 두 개의 XML 노드가 동일한지 비교할 때, 노드의 속성을 비교하려면 다음 방법을 사용할 수 있습니다.
1. XML 노드의 속성을 직접 비교하는 방법: XMLDiffBase::diff 함수에서 노드의 속성을 직접 비교할 수 있습니다. 예를 들어, 다음 코드를 사용할 수 있습니다.
#hostingforum.kr
cpp
xmlNodePtr node1 = ...; // 첫 번째 노드
xmlNodePtr node2 = ...; // 두 번째 노드
xmlAttr attr1 = node1->properties; // 첫 번째 노드의 속성
xmlAttr attr2 = node2->properties; // 두 번째 노드의 속성
// 속성 'id'와 'name'을 비교
if (xmlStrcmp(attr1->name, (const xmlChar*)"id") == 0 && xmlStrcmp(attr2->name, (const xmlChar*)"id") == 0 &&
xmlStrcmp(attr1->children->content, (const xmlChar*)"1") == 0 && xmlStrcmp(attr2->children->content, (const xmlChar*)"1") == 0) {
// 속성 'id'가 동일한 경우
} else {
// 속성 'id'가 다를 경우
}
if (xmlStrcmp(attr1->name, (const xmlChar*)"name") == 0 && xmlStrcmp(attr2->name, (const xmlChar*)"name") == 0 &&
xmlStrcmp(attr1->children->content, (const xmlChar*)"John") == 0 && xmlStrcmp(attr2->children->content, (const xmlChar*)"Jane") == 0) {
// 속성 'name'이 동일한 경우
} else {
// 속성 'name'이 다를 경우
}
2. XML 노드의 속성을 비교하는 함수를 만들기: 위의 방법을 반복할 필요없이 XML 노드의 속성을 비교하는 함수를 만들 수 있습니다.
#hostingforum.kr
cpp
xmlNodePtr compareNode(xmlNodePtr node1, xmlNodePtr node2) {
// 속성 'id'와 'name'을 비교
if (xmlStrcmp(node1->properties->name, (const xmlChar*)"id") == 0 && xmlStrcmp(node2->properties->name, (const xmlChar*)"id") == 0 &&
xmlStrcmp(node1->properties->children->content, (const xmlChar*)"1") == 0 && xmlStrcmp(node2->properties->children->content, (const xmlChar*)"1") == 0) {
// 속성 'id'가 동일한 경우
} else {
// 속성 'id'가 다를 경우
}
if (xmlStrcmp(node1->properties->name, (const xmlChar*)"name") == 0 && xmlStrcmp(node2->properties->name, (const xmlChar*)"name") == 0 &&
xmlStrcmp(node1->properties->children->content, (const xmlChar*)"John") == 0 && xmlStrcmp(node2->properties->children->content, (const xmlChar*)"Jane") == 0) {
// 속성 'name'이 동일한 경우
} else {
// 속성 'name'이 다를 경우
}
// 속성 비교 결과를 반환
return node1;
}
이러한 방법을 사용하면 XMLDiffBase::diff 함수에서 노드의 속성을 비교할 수 있습니다.
2025-07-20 12:38