XmlFindElementByAttribute
int64_t XmlFindElementByAttribute(int64_t parent, const char* elementName, const char* attrName, const char* attrValue, int32_t* err)
int32_t err = 0;
const char* xmlStr =
"<servers>"
" <server name=\"web\" host=\"192.168.1.1\"/>"
" <server name=\"db\" host=\"192.168.1.2\"/>"
" <server name=\"cache\" host=\"192.168.1.3\"/>"
"</servers>";
int64_t doc = XmlParse(xmlStr, &err);
int64_t root = XmlGetRootElement(doc, &err);
int64_t dbServer = XmlFindElementByAttribute(root, "server", "name", "db", &err);
if (dbServer != 0) {
const char* host = XmlGetAttribute(dbServer, "host", &err);
printf("数据库服务器:%s\n", host);
FreeStringPtr(instance, host);
}
int64_t cacheServer = XmlFindElementByAttribute(root, NULL, "host", "192.168.1.3", &err);
XmlFree(doc);