我正在尝试使用 NSXMLDocument验证 XML Schema 文档与模式( http://www.w3.org/2001/XMLSchema )的模式。我已经让它正常工作,并假设我正在针对本地模式进行验证。
但是,我发现没有网络连接,此验证不起作用。有没有办法强制 NSXMLDocument 使用本地模式进行验证?
我使用网络连接的代码:
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:(NSXMLDocumentValidate | NSXMLNodePreserveAll)
error:&err];
NSXMLElement *rootElement = [xmlDoc rootElement];
NSMutableArray *namespaces = [[rootElement namespaces] mutableCopy];
[namespaces addObject:[NSXMLNode namespaceWithName:@"xsi" stringValue:@"http://www.w3.org/2001/XMLSchema-instance"]];
[rootElement setNamespaces:namespaces];
[rootElement removeAttributeForName:@"xsi:schemaLocation"];
[rootElement addAttribute:[NSXMLNode attributeWithName:@"xsi:schemaLocation" stringValue:[NSString stringWithFormat:@"http://www.w3.org/2001/XMLSchema %@", @"/System/Library/Schemas/XMLSchema.xsd"]]];
BOOL vaildXML = [xmlDoc validateAndReturnError:&err];
我正在验证的文档的架构标签:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:myCompany="http://schema.myCompany.com/SomeSchema"
targetNamespace="http://schema.myCompany.com/SomeSchema">
w3.org 架构位置似乎有问题,但不是我公司的。
我看到的错误
错误:没有这样的文件或目录 I/O 警告:无法加载外部实体“http://www.w3.org/2001/xml.xsd”
错误域 = NSXMLParserErrorDomain 代码 = 1 UserInfo = 0x103051c10 “元素 '{http://www.w3.org/2001/XMLSchema}import':无法在位置 'http://www.w3.org/2001 找到架构/xml.xsd'。跳过导入。属性使用(未知),属性“ref”:QName 值“{http://www.w3.org/XML/1998/namespace}lang”不解析为( n) 属性声明。属性使用(未知),属性“ref”:QName 值“{http://www.w3.org/XML/1998/namespace}lang”不解析为 (n) 属性声明。
有任何想法吗?