我正在嘗試使用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)屬性聲明。
任何想法?