标签: nsxmldocument

无法#import <Foundation/NSXMLDocument.h>

我将NSXMLElement在我的项目中使用,所以我试着

#import <Foundation/NSXMLDocument.h> 
Run Code Online (Sandbox Code Playgroud)

但它给出了一个错误:"没有这样的文件或目录." 我怎么能包括这个?

import objective-c ios nsxmldocument

5
推荐指数
1
解决办法
3934
查看次数

NSXMLDocument,带有命名空间的nodesForXPath

我想从xml文件中获取一组元素,但是一旦元素涉及名称空间,它就会失败.

这是xml文件的一个片段:

<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     version="1.0" creator="Groundspeak Pocket Query"
     xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0 http://www.groundspeak.com/cache/1/0/cache.xsd" 
     xmlns="http://www.topografix.com/GPX/1/0"> 
  <name>My Finds Pocket Query</name>   
  <desc>Geocache file generated by Groundspeak</desc>   
  <author>Groundspeak</author>   
  <email>contact@groundspeak.com</email> 
  <time>2010-09-15T16:18:55.9846906Z</time> 
  <keywords>cache, geocache, groundspeak</keywords>   
  <bounds minlat="41.89687" minlon="5.561883" maxlat="70.669967" maxlon="25.74735" />    
  <wpt lat="62.244933" lon="25.74735">
    <time>2010-01-11T08:00:00Z</time>
    <name>GC22W1T</name>
    <desc>Kadonneet ja karanneet by ooti, Traditional Cache (1.5/2)</desc>
    <url>http://www.geocaching.com/seek/cache_details.aspx?guid=4af28fe9-401b-44df-b058-5fd5399fc083</url>
    <urlname>Kadonneet ja karanneet</urlname>
    <sym>Geocache Found</sym>
    <type>Geocache|Traditional Cache</type>
    <groundspeak:cache id="1521507" available="True" archived="False" xmlns:groundspeak="http://www.groundspeak.com/cache/1/0">
      <groundspeak:name>Kadonneet ja karanneet</groundspeak:name>
      <groundspeak:placed_by>ooti</groundspeak:placed_by>
      <groundspeak:owner id="816431">ooti</groundspeak:owner>
      <groundspeak:type>Traditional Cache</groundspeak:type>
      <groundspeak:container>Small</groundspeak:container>
      <groundspeak:difficulty>1.5</groundspeak:difficulty>
      <groundspeak:terrain>2</groundspeak:terrain>
      <groundspeak:country>Finland</groundspeak:country>
      <groundspeak:state>
      </groundspeak:state>
      <groundspeak:short_description html="True">
      </groundspeak:short_description>
      <groundspeak:encoded_hints>
      </groundspeak:encoded_hints> …
Run Code Online (Sandbox Code Playgroud)

cocoa xpath namespaces nsxmldocument

4
推荐指数
1
解决办法
3414
查看次数

带有solo标签的NSXMLElement.即.<tagname attributename = attributevalue />

我正在尝试创建一个应该包含solo标签的XML字符串(即.标签没有单独的结束标签)我能够创建正常的xml标签,如

<tagname attribute=attributevalue></tagname>
Run Code Online (Sandbox Code Playgroud)

使用代码

NSXMLElement *childElement=[[NSXMLElement alloc] initWithName:childName];
childElement.stringValue=childValue;
[childElement addAttribute:[NSXMLNode attributeWithName:attributeName stringValue:attributeValue]];
[self.currentNode addChild:[childElement copy]];
Run Code Online (Sandbox Code Playgroud)

但我需要这样的

<tagname attributename=attributevalue />
Run Code Online (Sandbox Code Playgroud)

macos objective-c nsxml nsxmldocument nsxmlelement

4
推荐指数
1
解决办法
1459
查看次数

打开文件时出现NSXMLDocument错误

我正在尝试将文件读入NSXMLDocument.这是我的代码:

NSString *urlString = [@"~/Library/Preferences/Quark/QuarkXPress 8/OutputStyles.xml" stringByExpandingTildeInPath];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];

NSError *error = nil;

NSXMLDocument *doc = [[NSXMLDocument alloc] initWithContentsOfURL:url options:0 error:&error];
NSLog(@"%@", error);
NSLog(@"%@", doc);
Run Code Online (Sandbox Code Playgroud)

但是,在控制台我得到:

2011-04-19 07:41:09.914 XMLTest[1409:a0f] Error Domain=NSURLErrorDomain Code=-1014 UserInfo=0x1001289d0 "zero byte resource"
2011-04-19 07:41:09.915 XMLTest[1409:a0f] (null)
Run Code Online (Sandbox Code Playgroud)

关于什么可能是错的任何建议?我有那里的文件..我检查了100次...谢谢.

编辑:当我尝试使用[stringwithcontentofurl encoding error]方法在NSString中读取此内容时,我收到此错误:

Error Domain = NSCocoaErrorDomain Code = 262 UserInfo = 0x1006281c0"无法打开文件,因为不支持指定的URL类型." 基础错误=(错误域= NSURLErrorDomain代码= -1002 UserInfo = 0x1006280d0"不支持的URL"基础错误=(错误域= kCFErrorDomainCFNetwork代码= -1002 UserInfo = 0x100627d50"不支持的URL"))

cocoa objective-c nsurl nsxmldocument

3
推荐指数
1
解决办法
2982
查看次数

使用NSXML Parser找不到用于XML解析的NSXMLDocument类

我一直试图尝试使用NSXML解析器解析xml文件.因为我想使用NSXMLDocument类在其实例中存储数据.在以各种可能的方式搜索之后,我未能清楚地了解NSXMLDocument.我没有特别为此导入任何课程.我必须添加任何类或lib文件???

nsxmlparser xml-parsing ipad ios nsxmldocument

1
推荐指数
1
解决办法
2933
查看次数