问题已解决......我在 TBXML 文档中找到了这个函数,它实际上提取了每个元素属性和属性值,非常简单......
使用一点 C 代码...
- (void) traverseElement:(TBXMLElement *)element {
do {
// Display the name of the element
NSLog(@"%@",[TBXML elementName:element]);
// Obtain first attribute from element
TBXMLAttribute * attribute = element->firstAttribute;
// if attribute is valid
while (attribute) {
// Display name and value of attribute to the log window
NSLog(@"%@->%@ = %@", [TBXML elementName:element],
[TBXML attributeName:attribute],
[TBXML attributeValue:attribute]);
// Obtain the next attribute
attribute = attribute->next;
}
// if the element has child elements, process them
if (element->firstChild)
[self traverseElement:element->firstChild];
// Obtain next sibling element
} while ((element = element->nextSibling));
}
如您所见,实际上发生了很多......递归、c 指针等。我像这样调用这个方法:
TBXML *configTBXML = [[TBXML alloc] initWithXMLData:[request responseData]];
TBXMLElement *root = configTBXML.rootXMLElement;
if (root) {
[self traverseElement:root];
}
这给出了以下输出:
2013-07-12 09:30:29.836 PowerOneApp[77609:3c07] data
2013-07-12 09:30:29.837 PowerOneApp[77609:3c07] data->timezone = US/Pacific-New-GMT-8
2013-07-12 09:30:29.837 PowerOneApp[77609:3c07] data->dst = 1
2013-07-12 09:30:29.838 PowerOneApp[77609:3c07] data->ts = 12-07-13 09:30:32
2013-07-12 09:30:29.838 PowerOneApp[77609:3c07] data->time = 12-07-13 09:30
2013-07-12 09:30:29.838 PowerOneApp[77609:3c07] data->sun = DAY
2013-07-12 09:30:29.838 PowerOneApp[77609:3c07] data->weblanguage = ENGLISH
2013-07-12 09:30:29.838 PowerOneApp[77609:3c07] data->datalivequeue_start = 0
2013-07-12 09:30:29.838 PowerOneApp[77609:3c07] data->datalivequeue_stop = 0
2013-07-12 09:30:29.839 PowerOneApp[77609:3c07] data->datalivequeue_cnt = 0
2013-07-12 09:30:29.839 PowerOneApp[77609:3c07] data->alarmsqueue_first = 229
2013-07-12 09:30:29.839 PowerOneApp[77609:3c07] data->alarmsqueue_last = 51
2013-07-12 09:30:29.839 PowerOneApp[77609:3c07] data->dhcpstatus = 6
2013-07-12 09:30:29.839 PowerOneApp[77609:3c07] data->gateway = OK
2013-07-12 09:30:29.839 PowerOneApp[77609:3c07] data->upgrade_portal = OK
2013-07-12 09:30:29.840 PowerOneApp[77609:3c07] data->data_portal = ERROR
2013-07-12 09:30:29.840 PowerOneApp[77609:3c07] data->msgdatalive = 564
2013-07-12 09:30:29.841 PowerOneApp[77609:3c07] data->upgrequests = 357
2013-07-12 09:30:29.841 PowerOneApp[77609:3c07] cdd
2013-07-12 09:30:29.841 PowerOneApp[77609:3c07] cdd->macrf = 00:12:4B:00:02:8A:E0:14
2013-07-12 09:30:29.841 PowerOneApp[77609:3c07] cdd->sn = 764040
2013-07-12 09:30:29.841 PowerOneApp[77609:3c07] cdd->countryselected = 2
2013-07-12 09:30:29.842 PowerOneApp[77609:3c07] cdd->countryname = USA 208V-60Hz
2013-07-12 09:30:29.842 PowerOneApp[77609:3c07] cdd->idmodel = 764040-3M60-1513
2013-07-12 09:30:29.842 PowerOneApp[77609:3c07] cdd->pout_kW = 0.0000
2013-07-12 09:30:29.842 PowerOneApp[77609:3c07] cdd->pout_W = 0.00
2013-07-12 09:30:29.843 PowerOneApp[77609:3c07] cdd->etot_Wh = 0.00
2013-07-12 09:30:29.843 PowerOneApp[77609:3c07] cdd->etot_kWh = 0.000
2013-07-12 09:30:29.843 PowerOneApp[77609:3c07] cdd->co2_t = 0.00
2013-07-12 09:30:29.843 PowerOneApp[77609:3c07] cdd->status = ALARM
2013-07-12 09:30:29.843 PowerOneApp[77609:3c07] edd
2013-07-12 09:30:29.844 PowerOneApp[77609:3c07] edd->sn = 957188
2013-07-12 09:30:29.844 PowerOneApp[77609:3c07] edd->pn = -3L03-
2013-07-12 09:30:29.844 PowerOneApp[77609:3c07] edd->type = edd
2013-07-12 09:30:29.844 PowerOneApp[77609:3c07] edd->macrf = 00:12:4B:00:02:6A:D6:27
2013-07-12 09:30:29.845 PowerOneApp[77609:3c07] edd->wy = 0413
2013-07-12 09:30:29.845 PowerOneApp[77609:3c07] edd->x = 1
2013-07-12 09:30:29.845 PowerOneApp[77609:3c07] edd->y = 1
2013-07-12 09:30:29.845 PowerOneApp[77609:3c07] edd->fwmicro = 0000
2013-07-12 09:30:29.846 PowerOneApp[77609:3c07] edd->p1_ids = 0000
2013-07-12 09:30:29.846 PowerOneApp[77609:3c07] edd->fwdsp = 0000
2013-07-12 09:30:29.846 PowerOneApp[77609:3c07] edd->p1_idi = 0000
2013-07-12 09:30:29.846 PowerOneApp[77609:3c07] edd->fwrf = 000
2013-07-12 09:30:29.846 PowerOneApp[77609:3c07] edd->Etot_Wh = 0.00
2013-07-12 09:30:29.847 PowerOneApp[77609:3c07] edd->Etot_kWh = 0.000
2013-07-12 09:30:29.847 PowerOneApp[77609:3c07] edd->Vout_V = 0.00
2013-07-12 09:30:29.847 PowerOneApp[77609:3c07] edd->Iout_A = 0.000
2013-07-12 09:30:29.847 PowerOneApp[77609:3c07] edd->Pout_W = 0.00
2013-07-12 09:30:29.848 PowerOneApp[77609:3c07] edd->Pout_kW = 0.0000
2013-07-12 09:30:29.848 PowerOneApp[77609:3c07] edd->Freq_Hz = 0.00
2013-07-12 09:30:29.848 PowerOneApp[77609:3c07] edd->Vin_V = 0.00
2013-07-12 09:30:29.848 PowerOneApp[77609:3c07] edd->Tdsp_degC = 0.00
2013-07-12 09:30:29.849 PowerOneApp[77609:3c07] edd->Tmos_degC = 0.00
2013-07-12 09:30:29.849 PowerOneApp[77609:3c07] edd->Pin_W = n.a
2013-07-12 09:30:29.849 PowerOneApp[77609:3c07] edd->Pin_kW = n.a
2013-07-12 09:30:29.849 PowerOneApp[77609:3c07] edd->Iin_A = n.a
2013-07-12 09:30:29.849 PowerOneApp[77609:3c07] edd->model = n.a
2013-07-12 09:30:29.850 PowerOneApp[77609:3c07] edd->eddmid = n.a
2013-07-12 09:30:29.850 PowerOneApp[77609:3c07] edd->cddid = n.a
2013-07-12 09:30:29.850 PowerOneApp[77609:3c07] edd->modeldesc = MICRO-0.3
2013-07-12 09:30:29.850 PowerOneApp[77609:3c07] edd->invstat = START-UP
2013-07-12 09:30:29.851 PowerOneApp[77609:3c07] edd->booststat = START-UP
2013-07-12 09:30:29.851 PowerOneApp[77609:3c07] edd->alarmstat = 1
2013-07-12 09:30:29.851 PowerOneApp[77609:3c07] edd->rssi = 0
2013-07-12 09:30:29.851 PowerOneApp[77609:3c07] edd->rssizero = 0
2013-07-12 09:30:29.851 PowerOneApp[77609:3c07] edd->rssicnt = 0
2013-07-12 09:30:29.852 PowerOneApp[77609:3c07] edd->rssiavg = 0
2013-07-12 09:30:29.852 PowerOneApp[77609:3c07] edd->msgcnt = 0
2013-07-12 09:30:29.852 PowerOneApp[77609:3c07] edd->samples = 15
2013-07-12 09:30:29.852 PowerOneApp[77609:3c07] edd->ts = 01-01-00 00:00:00
2013-07-12 09:30:29.853 PowerOneApp[77609:3c07] edd->dspalarm = 0x0000
2013-07-12 09:30:29.853 PowerOneApp[77609:3c07] edd->mcualarm = 0x8000
2013-07-12 09:30:29.853 PowerOneApp[77609:3c07] edd->mcuwarning = 0x0000
2013-07-12 09:30:29.853 PowerOneApp[77609:3c07] edd->CS_crc = 0x0000
2013-07-12 09:30:29.853 PowerOneApp[77609:3c07] edd
2013-07-12 09:30:29.854 PowerOneApp[77609:3c07] edd->sn = xxxxxx
2013-07-12 09:30:29.854 PowerOneApp[77609:3c07] edd->pn = xxxxxx
2013-07-12 09:30:29.854 PowerOneApp[77609:3c07] edd->type = edd
2013-07-12 09:30:29.854 PowerOneApp[77609:3c07] edd->macrf = 00:12:4B:00:02:6F:01:2C
2013-07-12 09:30:29.855 PowerOneApp[77609:3c07] edd->wy = xxxx
2013-07-12 09:30:29.855 PowerOneApp[77609:3c07] edd->x = 1
2013-07-12 09:30:29.855 PowerOneApp[77609:3c07] edd->y = 1
2013-07-12 09:30:29.855 PowerOneApp[77609:3c07] edd->fwmicro = 0000
2013-07-12 09:30:29.856 PowerOneApp[77609:3c07] edd->p1_ids = 0000
2013-07-12 09:30:29.856 PowerOneApp[77609:3c07] edd->fwdsp = 0000
2013-07-12 09:30:29.856 PowerOneApp[77609:3c07] edd->p1_idi = 0000
2013-07-12 09:30:29.856 PowerOneApp[77609:3c07] edd->fwrf = 000
2013-07-12 09:30:29.857 PowerOneApp[77609:3c07] edd->Etot_Wh = 0.00
2013-07-12 09:30:29.857 PowerOneApp[77609:3c07] edd->Etot_kWh = 0.000
2013-07-12 09:30:29.857 PowerOneApp[77609:3c07] edd->Vout_V = 0.00
2013-07-12 09:30:29.857 PowerOneApp[77609:3c07] edd->Iout_A = 0.000
2013-07-12 09:30:29.857 PowerOneApp[77609:3c07] edd->Pout_W = 0.00
2013-07-12 09:30:29.858 PowerOneApp[77609:3c07] edd->Pout_kW = 0.0000
2013-07-12 09:30:29.858 PowerOneApp[77609:3c07] edd->Freq_Hz = 0.00
2013-07-12 09:30:29.858 PowerOneApp[77609:3c07] edd->Vin_V = 0.00
2013-07-12 09:30:29.858 PowerOneApp[77609:3c07] edd->Tdsp_degC = 0.00
2013-07-12 09:30:29.859 PowerOneApp[77609:3c07] edd->Tmos_degC = 0.00
2013-07-12 09:30:29.859 PowerOneApp[77609:3c07] edd->Pin_W = n.a
2013-07-12 09:30:29.859 PowerOneApp[77609:3c07] edd->Pin_kW = n.a
2013-07-12 09:30:29.859 PowerOneApp[77609:3c07] edd->Iin_A = n.a
2013-07-12 09:30:29.859 PowerOneApp[77609:3c07] edd->model = n.a
2013-07-12 09:30:29.860 PowerOneApp[77609:3c07] edd->eddmid = n.a
2013-07-12 09:30:29.860 PowerOneApp[77609:3c07] edd->cddid = n.a
2013-07-12 09:30:29.860 PowerOneApp[77609:3c07] edd->modeldesc = MICRO-0.25
2013-07-12 09:30:29.860 PowerOneApp[77609:3c07] edd->invstat = START-UP
2013-07-12 09:30:29.861 PowerOneApp[77609:3c07] edd->booststat = START-UP
2013-07-12 09:30:29.861 PowerOneApp[77609:3c07] edd->alarmstat = 1
2013-07-12 09:30:29.861 PowerOneApp[77609:3c07] edd->rssi = 0
2013-07-12 09:30:29.861 PowerOneApp[77609:3c07] edd->rssizero = 0
2013-07-12 09:30:29.862 PowerOneApp[77609:3c07] edd->rssicnt = 0
2013-07-12 09:30:29.862 PowerOneApp[77609:3c07] edd->rssiavg = 0
2013-07-12 09:30:29.862 PowerOneApp[77609:3c07] edd->msgcnt = 0
2013-07-12 09:30:29.862 PowerOneApp[77609:3c07] edd->samples = 15
2013-07-12 09:30:29.862 PowerOneApp[77609:3c07] edd->ts = 01-01-00 00:00:00
2013-07-12 09:30:29.863 PowerOneApp[77609:3c07] edd->dspalarm = 0x0000
2013-07-12 09:30:29.863 PowerOneApp[77609:3c07] edd->mcualarm = 0x8000
2013-07-12 09:30:29.863 PowerOneApp[77609:3c07] edd->mcuwarning = 0x0000
2013-07-12 09:30:29.863 PowerOneApp[77609:3c07] edd->CS_crc = 0x0000
2013-07-12 09:30:29.864 PowerOneApp[77609:3c07] edd
2013-07-12 09:30:29.864 PowerOneApp[77609:3c07] edd->sn = xxxxxx
2013-07-12 09:30:29.864 PowerOneApp[77609:3c07] edd->pn = xxxxxx
2013-07-12 09:30:29.864 PowerOneApp[77609:3c07] edd->type = edd
2013-07-12 09:30:29.865 PowerOneApp[77609:3c07] edd->macrf = 00:12:4B:00:02:6F:14:5A
2013-07-12 09:30:29.865 PowerOneApp[77609:3c07] edd->wy = xxxx
2013-07-12 09:30:29.865 PowerOneApp[77609:3c07] edd->x = 1
2013-07-12 09:30:29.865 PowerOneApp[77609:3c07] edd->y = 1
2013-07-12 09:30:29.865 PowerOneApp[77609:3c07] edd->fwmicro = 0000
2013-07-12 09:30:29.866 PowerOneApp[77609:3c07] edd->p1_ids = 0000
2013-07-12 09:30:29.866 PowerOneApp[77609:3c07] edd->fwdsp = 0000
2013-07-12 09:30:29.866 PowerOneApp[77609:3c07] edd->p1_idi = 0000
2013-07-12 09:30:29.866 PowerOneApp[77609:3c07] edd->fwrf = 000
2013-07-12 09:30:29.867 PowerOneApp[77609:3c07] edd->Etot_Wh = 0.00
2013-07-12 09:30:29.867 PowerOneApp[77609:3c07] edd->Etot_kWh = 0.000
2013-07-12 09:30:29.867 PowerOneApp[77609:3c07] edd->Vout_V = 0.00
2013-07-12 09:30:29.867 PowerOneApp[77609:3c07] edd->Iout_A = 0.000
2013-07-12 09:30:29.868 PowerOneApp[77609:3c07] edd->Pout_W = 0.00
2013-07-12 09:30:29.868 PowerOneApp[77609:3c07] edd->Pout_kW = 0.0000
2013-07-12 09:30:29.868 PowerOneApp[77609:3c07] edd->Freq_Hz = 0.00
2013-07-12 09:30:29.868 PowerOneApp[77609:3c07] edd->Vin_V = 0.00
2013-07-12 09:30:29.869 PowerOneApp[77609:3c07] edd->Tdsp_degC = 0.00
2013-07-12 09:30:29.869 PowerOneApp[77609:3c07] edd->Tmos_degC = 0.00
2013-07-12 09:30:29.869 PowerOneApp[77609:3c07] edd->Pin_W = n.a
2013-07-12 09:30:29.869 PowerOneApp[77609:3c07] edd->Pin_kW = n.a
2013-07-12 09:30:29.870 PowerOneApp[77609:3c07] edd->Iin_A = n.a
2013-07-12 09:30:29.870 PowerOneApp[77609:3c07] edd->model = n.a
2013-07-12 09:30:29.870 PowerOneApp[77609:3c07] edd->eddmid = n.a
2013-07-12 09:30:29.870 PowerOneApp[77609:3c07] edd->cddid = n.a
2013-07-12 09:30:29.870 PowerOneApp[77609:3c07] edd->modeldesc = MICRO-0.25
2013-07-12 09:30:29.871 PowerOneApp[77609:3c07] edd->invstat = START-UP
2013-07-12 09:30:29.871 PowerOneApp[77609:3c07] edd->booststat = START-UP
2013-07-12 09:30:29.871 PowerOneApp[77609:3c07] edd->alarmstat = 1
2013-07-12 09:30:29.871 PowerOneApp[77609:3c07] edd->rssi = 0
2013-07-12 09:30:29.872 PowerOneApp[77609:3c07] edd->rssizero = 0
2013-07-12 09:30:29.872 PowerOneApp[77609:3c07] edd->rssicnt = 0
2013-07-12 09:30:29.872 PowerOneApp[77609:3c07] edd->rssiavg = 0
2013-07-12 09:30:29.872 PowerOneApp[77609:3c07] edd->msgcnt = 0
2013-07-12 09:30:29.873 PowerOneApp[77609:3c07] edd->samples = 15
2013-07-12 09:30:29.873 PowerOneApp[77609:3c07] edd->ts = 01-01-00 00:00:00
2013-07-12 09:30:29.873 PowerOneApp[77609:3c07] edd->dspalarm = 0x0000
2013-07-12 09:30:29.873 PowerOneApp[77609:3c07] edd->mcualarm = 0x8000
2013-07-12 09:30:29.874 PowerOneApp[77609:3c07] edd->mcuwarning = 0x0000
2013-07-12 09:30:29.874 PowerOneApp[77609:3c07] edd->CS_crc = 0x0000