-- 作者:world39
-- 发布时间:9/13/2007 2:58:00 PM
-- 新手请教:这个xml 文件 明显不符合schema的格式限制,为什么还可以正常load?
新手请教:这个xml 文件 明显不符合schema的格式限制,为什么还可以正常load? books.xml <?xml version='1.0'?> <Collection xmlns="x-schema:books"> <Book> <Title>Lover Birds</Title> <Author>Cynthia Randall</Author> <Title>Lover Birds</Title> <Title>the secord title</Title> <Title>the third title</Title> <Publisher>Lucerne Publishing</Publisher> </Book> </Collection> books.xsd <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Collection"> <xs:complexType> <xs:sequence> <xs:element name="OtherBook"> <xs:complexType> <xs:sequence> <xs:element name="Title" type="xs:string" maxOccurs="1" /> <xs:element name="Author" type="xs:string" /> <xs:element name="Publisher" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> 用vc写的验证的接口 bool CURLManagerApp::schemas() { ::CoInitialize(NULL); IXMLDOMDocument2Ptr pIXMLDOMDocument2; IXMLDOMSchemaCollection2Ptr pIXMLDOMSchemaCollection2Ptr; int nResult; try { // Create the DOM nResult = pIXMLDOMDocument2.CreateInstance(__uuidof(MSXML2::DOMDocument40)); (nResult == 0) ? 0: throw nResult; // Create the Schema Collections nResult = pIXMLDOMSchemaCollection2Ptr.CreateInstance(__uuidof(MSXML2::XMLSchemaCache40)); (nResult == 0) ? 0: throw nResult; // Add the schema to the collection nResult = pIXMLDOMSchemaCollection2Ptr->add(_T("x-schema:books"), _T("books.xsd")); (nResult == 0) ? 0: throw nResult; // Attach schemas pIXMLDOMDocument2->schemas = pIXMLDOMSchemaCollection2Ptr.GetInterfacePtr(); pIXMLDOMDocument2->async = false; pIXMLDOMDocument2->validateOnParse = true; // Load the document into the DOM nResult = pIXMLDOMDocument2->load(_T("books.xml")); (nResult == -1) ? 0: throw nResult; ::MessageBox(NULL, pIXMLDOMDocument2->xml, _T("Loaded Document"), MB_OK); } catch(...) { ::MessageBox(NULL, _T("Sample Failed"), _T("Error"), MB_OK); } ::CoUninitialize(); return true; } 这个books.xml中 autor 和title的顺序不符合books.xsd,而且title也出现了不止1次,为什么在程序中books.xml还是会正常导入呢? 当xml文件不符合xsd文件规则时,不是应该load失败吗? 再问怎么截获load失败信息啊?? 我是新手,这个问题很弱智,希望达人解答。万谢!
|