获取属性数量 - XmlGetAttributeCount
函数简介
获取元素的属性数量。
接口名称
XmlGetAttributeCount
DLL调用
int32_t XmlGetAttributeCount(int64_t element, int32_t* err)
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| element | int64_t | 元素句柄 |
| err | int32_t* | 错误码输出参数,可为NULL |
示例
int32_t err = 0;
int64_t doc = XmlParse("<server host=\"localhost\" port=\"8080\"/>", &err);
int64_t root = XmlGetRootElement(doc, &err);
int32_t count = XmlGetAttributeCount(root, &err);
printf("属性数量:%d\n", count); // 输出:2
XmlFree(doc);
返回值
| 返回值类型 | 说明 |
|---|---|
| int32_t | 返回属性数量,失败时返回0 |
注意事项
- 如果元素没有属性,返回0
- 可用于判断元素是否有属性
