- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 TBXML 解析器来解析一些大的 xml 文件。 xml 文件的结构如下:
<Products>
<Category>
<product></product>
</Category>
</Products>
这是我用来解析 xml 的代码:
- (void)loadURL {
// Load and parse an xml string
Products *product = [[Products alloc] init];
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:@"SOMELINK"]];
// If TBXML found a root node, process element and iterate all children
// Obtain root element
TBXMLElement * root = tbxml.rootXMLElement;
// if root element is valid
if (root) {
// search for the first category element within the root element's children
TBXMLElement *Category = [TBXML childElementNamed:@"Category" parentElement:root];
product.category = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category];
NSLog(@"%@", product.category);
// if an author element was found
while ([[TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category] isEqualToString:@"Dames"]) {
product.category = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category];
TBXMLElement *xmlProduct = [TBXML childElementNamed:@"Product" parentElement:Category];
while (xmlProduct != nil) {
Products *product = [[Products alloc] init];
// extract the title attribute from the book element
product.productId = [TBXML valueOfAttributeNamed:@"Id" forElement:xmlProduct];
product.material = [TBXML valueOfAttributeNamed:@"Material" forElement:xmlProduct];
product.color = [TBXML valueOfAttributeNamed:@"Color" forElement:xmlProduct];
product.heel = [TBXML valueOfAttributeNamed:@"Heel" forElement:xmlProduct];
product.lining = [TBXML valueOfAttributeNamed:@"Lining" forElement:xmlProduct];
product.subcategory = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:xmlProduct];
NSString * price = [TBXML valueOfAttributeNamed:@"Price" forElement:xmlProduct];
// if we found a price
if (price != nil) {
// obtain the price from the book element
product.price = [NSNumber numberWithFloat:[price floatValue]];
}
// add the book object to the dames array and release the resource
[dames addObject:product];
[product release];
// find the next sibling element named "xmlProduct"
xmlProduct = [TBXML nextSiblingNamed:@"Product" searchFromElement:xmlProduct];
}
// find the next sibling element named "Category"
Category = [TBXML nextSiblingNamed:@"Category" searchFromElement:Category];
}
while ([[TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category] isEqualToString:@"Accessoires"]) {
product.category = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category];
TBXMLElement *xmlProduct = [TBXML childElementNamed:@"Product" parentElement:Category];
while (xmlProduct != nil) {
Products *product = [[Products alloc] init];
product.productId = [TBXML valueOfAttributeNamed:@"Id" forElement:xmlProduct];
product.material = [TBXML valueOfAttributeNamed:@"Material" forElement:xmlProduct];
product.color = [TBXML valueOfAttributeNamed:@"Color" forElement:xmlProduct];
product.subcategory = [TBXML valueOfAttributeNamed:@"DisplayName" forElement:xmlProduct];
product.heel = [TBXML valueOfAttributeNamed:@"Heel" forElement:xmlProduct];
product.lining = [TBXML valueOfAttributeNamed:@"Lining" forElement:xmlProduct];
NSString * price = [TBXML valueOfAttributeNamed:@"Price" forElement:xmlProduct];
// if we found a price
if (price != nil) {
// obtain the price from the book element
product.price = [NSNumber numberWithFloat:[price floatValue]];
}
[tassen addObject:product];
[product release];
xmlProduct = [TBXML nextSiblingNamed:@"Product" searchFromElement:xmlProduct];
}
// find the next sibling element named "Category"
Category = [TBXML nextSiblingNamed:@"Category" searchFromElement:Category];
}
}
}
我总共有 4 个类别(因为上面的代码不相关,所以去掉中间的 2 个)。当我解析前 3 个类别时一切正常,但当我解析到最后一个时,就会发生一些奇怪的事情。
Category = [TBXML nextSiblingNamed:@"Category"searchFromElement:Category];
行将搜索一个新类别,但由于没有,它将返回 null。我会说解析器是否已完成,但此时解析器崩溃并在 TBXML.M 文件(来自 tbxml api)中的以下代码中给出 EXC_BAD_ACCESS:
TBXMLAttribute * attribute = aXMLElement->firstAttribute;
我不知道为什么,但也许这里有人会马上看到它...任何帮助将不胜感激!
提前致谢!
最佳答案
问题解决了:
此代码给出了错误的访问权限:
while ([[TBXML valueOfAttributeNamed:@"DisplayName" forElement:Category] isEqualToString:@"Accessoires"])
用 while (category !=nil) 解决了它,它起作用了
关于iphone - TBXML 解析器给出 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6691371/
我遇到问题包括 TBXML在我的项目中。 guide告诉我包含四个文件,TBXML.h、TBXML.m、NSDataAdditions.h 和 NSDataAdditions.m,但在 the Git
我在我的 iphone 应用程序中使用 TBXML。我有一个类似下一个的 xml: My title subCategory1 subCategory2
我在我的一个项目中使用 TBXML,我想知道 例如,有没有办法检查标签是否不包含文本 对比 This is text 当我使用调试器并输入 po [TBXML textForElement:gr
我有这个 xml: 为了解析它,我使用 [TBXML valueOfAttributeNamed:@
基本上我有一个返回的 XML 响应和一个字符串,我需要遍历 xml 并将所有信息存储在一个数组中。这是 xml 00 OK
对于这个元素,我总是得到 null:Rua Santo Ubaldo, 28 - São Paulo xml文件: 1 Woods Bar
所以我在查找 XML 文件的元素中的未定义元素时遇到了问题。 我能够解析元素“item”... 14459 现在,如果您注意到,在“item”元素的末尾,有一个我需要存储的未定义键……我该怎么做呢?这
我正在使用 TBXML 解析器来解析一些大的 xml 文件。 xml 文件的结构如下: 这是我用来解析 xml 的代码: - (void)loadURL { // Load and
绞尽脑汁想弄清楚这个问题。 TBXML 必须设置 rootXMLElement 才能开始遍历和解析数据。 无论我做什么,当我NSLog 它时,它都是空的。 这是 XML 的示例:
我正在使用 TBXML 进行 XML feed 解析,并使用工具来检测内存泄漏。 仪器告诉我函数中存在内存泄漏 - (TBXMLAttribute*) nextAvailableAttribute {
我的 XML 看起来像这样: 11 22
我正在尝试使用适用于 iOS 的 TBXML 库解析 HTML,并且我想获得这段 HTML 的“更多文本”值: value more text 我用过这段代码,但它似乎不起作用:
我正在使用 TBXML 解析器版本。 1.4,当我通过 TBXML 解析器解析这种后续响应时,得到 EXC_BAD_ACCESS... ~!@#$%^&*()_+?> 遇到这个问题。 据我观察,TB
您好,我有一个解析器可以测试可能出现的错误,例如 D_TBXML_ELEMENT_TEXT_IS_NIL。如果 obj1 是 nil 并且 obj2 有文本 (NSError *) 错误仍然返回一个非
我使用 TBXML 的方法收到内存泄漏解析 XML 文件。 它给我 NSCFString 'Leaked Objects' with。当我查看堆栈跟踪时,它的最后一次调用是使用 TBXML 方法 te
我正在尝试使用 TBXML,我想通过发送用户名和密码来解析 xml,但不知道该怎么做,我已经学习了很多教程。 -(IBAction)login{ NSStr
我有一个 xml 响应需要设置到一个数组中。问题是我需要访问每个元素并将其存储在一个数组中,以便我可以将它用于 tableview。 00 OK
我打算将 TBXML 用于我的天气应用程序。到目前为止,我已经将 NSXMLParser 与 NSURLConnection 一起使用,但我觉得这必须能够更简单、更快和更稳定(当前代码非常复杂,小问题
这是我的问题: 我在我的 iPad 应用程序中使用 TBXML。 XML 服务器响应以 xml 描述行开始: 并且 TBXML 无法解析节点(即 nextSibling 方法变为空)。将 XML 转
我尝试从TBXML开始,但是我不明白它是如何工作的... 如何从文档中获取所有img标签(作为TBXMLElement)? 最佳答案 您阅读指南了吗?从here开始,然后继续here。您提到您试图从文
我是一名优秀的程序员,十分优秀!