路径查询元素 - XmlQueryElement
函数简介
使用路径查询元素。
接口名称
XmlQueryElement
DLL调用
int64_t XmlQueryElement(int64_t doc, const char* path, int32_t* err)
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| doc | int64_t | XML文档句柄 |
| path | string | 查询路径(如 "root/child/item") |
| err | int32_t* | 错误码输出参数,可为NULL |
示例
int32_t err = 0;
const char* xmlStr =
"<config>"
" <server>"
" <database>"
" <connection>mysql://localhost</connection>"
" </database>"
" </server>"
"</config>";
int64_t doc = XmlParse(xmlStr, &err);
// 使用路径查询
int64_t conn = XmlQueryElement(doc, "config/server/database/connection", &err);
if (conn != 0) {
const char* text = XmlGetElementText(conn, &err);
printf("连接字符串:%s\n", text);
FreeStringPtr(instance, text);
}
XmlFree(doc);
返回值
| 返回值类型 | 说明 |
|---|---|
| int64_t | 返回找到的元素句柄,失败时返回0 |
注意事项
- 路径使用"/"分隔元素名称
- 路径区分大小写
- 如果路径不存在,返回0
