我正在尝试使用NSXMLDocument针对模式架构(http://www.w3.org/2001/XMLSchema)验证XML模式文档。我已经使它正常工作,并假定我正在验证本地模式。NSXMLDocument validateAndReturnError需要网络连接?
但是,我发现没有网络连接,此验证不起作用。有没有办法强制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的一个问题。组织架构位置,但不是我公司的。
我看到
错误的错误:没有这样的文件或目录 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':Th e QName值'{http://www.w3.org/XML/1998/namespace}lang'不解析为(n)属性声明。
任何想法?