获取子元素数量 - XmlGetChildCount
函数简介
获取元素的子元素数量。
接口名称
XmlGetChildCount
DLL调用
int32_t XmlGetChildCount(int64_t element, int32_t* err)
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| element | int64_t | 元素句柄 |
| err | int32_t* | 错误码输出参数,可为NULL |
示例
int32_t err = 0;
int64_t doc = XmlParseFile("config.xml", &err);
int64_t root = XmlGetRootElement(doc, &err);
int32_t count = XmlGetChildCount(root, &err);
printf("子元素数量:%d\n", count);
XmlFree(doc);
返回值
| 返回值类型 | 说明 |
|---|---|
| int32_t | 返回子元素数量,失败时返回0 |
注意事项
- 只统计直接子元素,不包括孙子元素
- 如果没有子元素,返回0
