根据名称获取同名子元素数量 - XmlGetChildCountByName
函数简介
根据名称获取所有匹配的子元素数量。
接口名称
XmlGetChildCountByName
DLL调用
int32_t XmlGetChildCountByName(int64_t parent, const char* name, int32_t* err)
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| parent | int64_t | 父元素句柄 |
| name | string | 元素名称 |
| err | int32_t* | 错误码输出参数,可为NULL |
示例
int32_t err = 0;
const char* xmlStr =
"<root>"
" <item>A</item>"
" <item>B</item>"
" <item>C</item>"
" <other>D</other>"
"</root>";
int64_t doc = XmlParse(xmlStr, &err);
int64_t root = XmlGetRootElement(doc, &err);
int32_t itemCount = XmlGetChildCountByName(root, "item", &err);
printf("item元素数量:%d\n", itemCount); // 输出:3
XmlFree(doc);
返回值
| 返回值类型 | 说明 |
|---|---|
| int32_t | 返回匹配的子元素数量,失败时返回0 |
注意事项
- 只统计直接子元素
- 名称区分大小写
- 如果没有匹配的元素,返回0
