
속성이 존재하지 않는 경우 NULL을 반환하는 방법은 다음과 같습니다.
#hostingforum.kr
cpp
const xmlChar* attr = xmlReader->getAttributeNs(writer, (const xmlChar*)"http://example.com", (const xmlChar*)"example");
if (attr == NULL) {
// 속성이 존재하지 않습니다.
attr = "";
}
속성이 존재하지 않으면 예외를 발생시키지 않도록 하려면, 다음과 같이 NULL 체크를 하거나, `xmlGetProp` 함수를 사용하여 속성을 가져올 수 있습니다.
#hostingforum.kr
cpp
const xmlChar* attr = xmlReader->getAttributeNs(writer, (const xmlChar*)"http://example.com", (const xmlChar*)"example");
if (attr == NULL) {
// 속성이 존재하지 않습니다.
attr = "";
} else {
// 속성이 존재합니다.
}
또한, `xmlGetProp` 함수를 사용하여 속성을 가져올 수 있습니다.
#hostingforum.kr
cpp
const xmlChar* attr = xmlGetProp(reader, (const xmlChar*)"http://example.com", (const xmlChar*)"example");
if (attr == NULL) {
// 속성이 존재하지 않습니다.
attr = "";
} else {
// 속성이 존재합니다.
}
이러한 방법을 사용하여, 속성이 존재하지 않으면 예외를 발생시키지 않도록 할 수 있습니다.
2025-04-09 03:13