Post by szemranyPost by ktosMasz jakąś sugestię jak to robić?
http://stackoverflow.com/questions/446635/schema-validation-with-msxml-in-delphi
Ale sprawdzałeś czy to działa?
function TForm1.ValidXML(const xmlFile: String;
out err: IXMLDOMParseError): Boolean;
var
xml, xsd: IXMLDOMDocument2;
cache: IXMLDOMSchemaCollection;
s: String;
begin
xsd := CoDOMDocument40.Create;
xsd.Async := False;
xsd.load('http://www.mf.gov.pl/documents/764034/5134536/Schemat_JPK_KR%281%29_v1-0.xsd');
cache := CoXMLSchemaCache40.Create;
try
cache.add('http://jpk.mf.gov.pl/wzor/2016/03/09/03091/', xsd);
except
//tylko po to aby łatwo pobrać w Delphi błąd
ON E:Exception Do
begin
s:=E.Message;
Showmessage(s);
end;
end;
xml := CoDOMDocument40.Create;
xml.async := False;
xml.schemas := cache;
Result := xml.load(xmlFile);
if not Result then
err := xml.parseError
else
err := nil;
end
Odpowiedź:
'http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/ElementarneTypyDanych_v4-0E.xsd#/schema[1]/simpleType[position()
= 35 and @name = ''TNrDokumentu'']/restriction[1]'#$A'It is an error for
both length and minLength or maxLength to be present'
Druga funkcja
function TForm1.ValidXML2(const xmlFile: String;
out err: IXMLDOMParseError): Boolean;
var
xml, xml2, xsd: IXMLDOMDocument2;
schemas, cache: IXMLDOMSchemaCollection;
begin
xml := CoDOMDocument.Create as IXMLDOMDocument2;
if xml.load(xmlFile) then
begin
schemas := xml.namespaces;
if schemas.length > 0 then
begin
xsd := CoDOMDocument40.Create;
xsd.Async := False;
xsd.load(schemas.namespaceURI[0]);
cache := CoXMLSchemaCache40.Create;
cache.add(schemas.namespaceURI[1], xsd);
xml2 := CoDOMDocument40.Create;
xml2.async := False;
xml2.schemas := cache;
Result := xml2.load(xmlFile);
//err := xml.validate;
if not Result then
err := xml2.parseError
else
err := nil;
end;
end;
end;
schemas.namespaceURI[0]=>'http://jpk.mf.gov.pl/wzor/2016/03/09/03091/'
schemas.namespaceURI[1]=>''http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/''
przy ładowaniu xsd.load(schemas.namespaceURI[0]);
'Odmowa dostępu'
przy ładowaniu xsd.load(schemas.namespaceURI[1]);
'Parametr jest niepoprawny'