Bohao LI Bohao LI - 5 months ago 26
C Question

how to get the keys of a xmlHashTable ? (libxml2)

I am using the library libxml2 to parse an XML document. And then I saw

in this library. Is it possible to get all the keys of a
? I want to store all the keys in an array.

The XML document is:

<?xml version="1.0" encoding="UTF-8"?>

<?type-proto key="MIPRegistrationRequest" value="mip" ?>
<?avp-proto key="Example-AVP" value="data" ?>

<!DOCTYPE dictionary SYSTEM "dictionary.dtd" [
<!-- Any files added here need to be added to and
packaging/nsis/wireshark.nsi -->

<!ENTITY nasreq SYSTEM "nasreq.xml">
<!ENTITY eap SYSTEM "eap.xml">
<!ENTITY mobileipv4 SYSTEM "mobileipv4.xml">
<!ENTITY chargecontrol SYSTEM "chargecontrol.xml">
<!ENTITY sunping SYSTEM "sunping.xml">
<!ENTITY sip SYSTEM "sip.xml">
<!ENTITY etsie2e4 SYSTEM "etsie2e4.xml">
<!ENTITY Ericsson SYSTEM "Ericsson.xml">
<!ENTITY mobileipv6 SYSTEM "mobileipv6.xml">
<!ENTITY Cisco SYSTEM "Cisco.xml">
<!ENTITY Starent SYSTEM "Starent.xml">
<!ENTITY Vodafone SYSTEM "Vodafone.xml">
<!ENTITY AlcatelLucent SYSTEM "AlcatelLucent.xml">
<!ENTITY Nokia SYSTEM "Nokia.xml">
<!ENTITY NokiaSolutionsAndNetworks SYSTEM "NokiaSolutionsAndNetworks.xml">
<!ENTITY Oracle SYSTEM "Oracle.xml">
<!ENTITY Custom SYSTEM "Custom.xml">

I am trying to get the all the keys of the external (parsed) entities (such as nasreq, eap etc):

ddict_t *ddict_scan(const char* system_directory, const char* filename)

char *path = g_strconcat((const gchar*) system_directory, (const gchar*)filename, (const gchar *)'\0');
xmlDocPtr p1 = getdoc((const char *)path);
xmlEntitiesTablePtr ptr2 = p1->intSubset->entities;
//to be added

The type of
is a


There is the xmlHashScan() function (and its pickier relatives), which can be used to have a user-provided xmlHashScanner function called back by the library for each entry in the xmlHashTable. The xmlHashScanner is given the name of each entry as parameter, so it should be easy to assemble a list of all the keys that way.