有人可以告诉我如何使用 tbxml 正确遍历给定的 xml 结构吗?我正在使用附加的代码进行 TBXML 解析。我能够获得 id 和 name 标签的值。但是该方法没有检测到标题和描述标签中的值。
-(void)traverseElement:(TBXMLElement *)element
{
do
{
[TBXML iterateAttributesOfElement:element withBlock:^(TBXMLAttribute *attribute, NSString *name, NSString *value) {
NSLog(@"%@->%@ = %@",[TBXML elementName:element], name, value);
}];
if (element->firstChild)
[self traverseElement:element->firstChild];
}
while ((element = element->nextSibling));
}
xml结构是 -
<allresponse>
<responses>
<response id="123" name ="myname1">
<title> Some Title1 </title>
<description>Some decription 1</description>
</response>
<response id="456" name ="myname2">
<title> Some Title2 </title>
<description>Some decription 2</description>
</response>
</responses>
</allresponse>