在 xpath 查询中使用变量..可能吗?

发布于 2024-09-07 04:42:21 字数 1199 浏览 5 评论 0原文

有人可以告诉我如何在 iPhone 的 c-objective 中的 XPath 查询中使用带有变量的文本函数吗? 中存在的工程库信息

我需要 xml http://www.sis 。 pitt.edu/~arazeez/Librarydata.xml

NSString *libName = @"Engineering Library";
    NSMutableString  *xpathquery = [[NSMutableString alloc] init];
    [xpathquery appendString:@"//Library[LibraryName/text() = '"];
    [xpathquery appendString:libName];
    [xpathquery appendString:@"']/../Hours/TermOrHolidays"];
    resultNodes = [rssParser nodesForXPath:xpathquery error:nil];

或其他变体

NSString *string1 = @"//LibraryName[text() = '"; 
NSString *string2 = @"']/../Hours/TermOrHolidays"; 
NSString *newString; NSString *newString1; 
newString = [string1 stringByAppendingString:libName]; 
newString1 = [newString stringByAppendingString:string2]; 
NSLog(newString1);
 //correct one below //resultNodes = [rssParser nodesForXPath:@"//LibraryName[text()= 'Engineering Library']/../Hours/TermOrHolidays" error:nil]; 

resultNodes = [rssParser nodeForXPath:newString1 error:nil];

如果此方法不正确,请有人告诉我如何获取工程图书馆的数据。我不想直接使用这个词,而是想通过变量使用它。

谢谢

Could some one please tell me how do we use the text function with variable in the XPath query in c-objective for iphone. I needed the information for Engineering Library present in the xml

http://www.sis.pitt.edu/~arazeez/Librarydata.xml

NSString *libName = @"Engineering Library";
    NSMutableString  *xpathquery = [[NSMutableString alloc] init];
    [xpathquery appendString:@"//Library[LibraryName/text() = '"];
    [xpathquery appendString:libName];
    [xpathquery appendString:@"']/../Hours/TermOrHolidays"];
    resultNodes = [rssParser nodesForXPath:xpathquery error:nil];

or another variant

NSString *string1 = @"//LibraryName[text() = '"; 
NSString *string2 = @"']/../Hours/TermOrHolidays"; 
NSString *newString; NSString *newString1; 
newString = [string1 stringByAppendingString:libName]; 
newString1 = [newString stringByAppendingString:string2]; 
NSLog(newString1);
 //correct one below //resultNodes = [rssParser nodesForXPath:@"//LibraryName[text()= 'Engineering Library']/../Hours/TermOrHolidays" error:nil]; 

resultNodes = [rssParser nodeForXPath:newString1 error:nil];

If this method is not right, could some one please tell me how to fetch the data for Engineering Library. I dont want to use the word directly but want to use it through a variable.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

背叛残局 2024-09-14 04:42:21

使用 [NSString stringWithFormat:@"//LibraryName[text() = '%@']/../Hours/TermOrHolidays", someVariable] 构造字符串可能会更容易

然后只要 xpath 查询没问题就可以工作。

It might be easier to construct the string using [NSString stringWithFormat:@"//LibraryName[text() = '%@']/../Hours/TermOrHolidays", someVariable]

Then as long as the xpath query is okay it will work.

笔芯 2024-09-14 04:42:21

使用这个 xpath:

//Library[@name='Engineering Library']/Hours/TermOrHolidays

或这个:怎么样?

//Library[LibraryName='Engineering Library']/Hours/TermOrHolidays

how about using this xpath:

//Library[@name='Engineering Library']/Hours/TermOrHolidays

or this one:

//Library[LibraryName='Engineering Library']/Hours/TermOrHolidays
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文