Article View: pl.comp.lang.delphi
Article #346924Jak sprawdzacie poprawność xlm względem XSD
From: konsul41
Date: Thu, 31 Jan 2019 10:37
Date: Thu, 31 Jan 2019 10:37
86 lines
3796 bytes
3796 bytes
Zależy mi na tym aby funkcja przyjmowała jako argument tylko nazw pliku
do validacji
Przykład JPK_VAT
<tns:JPK
xmlns:tns="http://jpk.mf.gov.pl/wzor/2017/11/13/1113/"
xmlns:etd="http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Jeżeli tak
ioXMLDOMDoc := CreateDOMDocument;
with ioXMLDOMDoc do begin
async := False;
validateOnParse := true;
resolveExternals := True;
LoadFromXMLString(ioXMLDOMDoc,XMLDoc.XML.Text);
if parseError.errorCode <> 0 then
...
to sprawdzi mi tylko tagi ...
A interesuje mnie sprawdzanie merytoryczne np: pole wymagane które jest
puste
np: <tns:NrKontrahenta> </tns:NrKontrahenta>
lub Poprawność nip z dziennikiem urzędowym Uni Europejskiej
np <tns:NrKontrahenta>ATU...</tns:NrKontrahenta>
Jeżeli tak zrobię
function ValidXML2(const xmlFile: String; out err: IXMLDOMParseError):
Boolean;
var
xml, xml2, xsd: IXMLDOMDocument2;
schemas, cache: IXMLDOMSchemaCollection;
i : Integer;
begin
xml := CoDOMDocument.Create;
if xml.load(xmlFile) then
begin
schemas := xml.namespaces;
if schemas.length > 0 then
begin
xsd := CoDOMDocument40.Create;
xsd.Async := False;
cache := CoXMLSchemaCache40.Create;
for i := 0 to schemas.length-1 do
begin
try
if xsd.load(schemas.namespaceURI[i]) then
begin
cache.add(schemas.namespaceURI[i], xsd);
end;
except
On E:Exception DO
begin
ShowMessage('Błąd dostępu do przestrzeni nazw
'+schemas.namespaceURI[i] +#13+E.Message);
end;
end;
end;
xml2 := CoDOMDocument40.Create;
xml2.async := False;
xml2.schemas := cache;
Result := xml2.load(xmlFile);
if not Result then
err := xml2.parseError
else
err := nil;
end;
end;
end;
to wyrzuca mi brak dostępu do
1- http://jpk.mf.gov.pl/wzor/2017/11/13/1113/
'Błąd dostępu do przestrzeni nazw
http://jpk.mf.gov.pl/wzor/2017/11/13/1113/'#$D'Odmowa dostępu'
2-
'Błąd dostępu do przestrzeni nazw
http://www.w3.org/2001/XMLSchema-instance'#$D'http://www.w3.org/2001/XMLSchema-instance#/schema[1]/attribute[position()
= 1 and @name = ''nil'']'#$A'Schema''s targetNamespace attribute must
not match ''http://www.w3.org/2000/10/Schema-instance'''
Nie ma błędu za to przy
http://crd.gov.pl/xml/schematy/dziedzinowe/mf/2016/01/25/eD/DefinicjeTypy/
Technical Details
Message-ID:
<5c52cfce$0$498$65785112@news.neostrada.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!85.12.16.70.MISMATCH!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-b-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed9.news.xs4all.nl!85.12.16.70.MISMATCH!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.fr7!futter-mich.highwinds-media.com!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-b-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail Newsgroups: pl.comp.lang.delphi X-Mozilla-News-Host: news://news.neostrada.pl:119 From: "konsul41@wp.pl" <konsul41@wp.pl> Subject: Jak sprawdzacie poprawność xlm względem XSD Date: Thu, 31 Jan 2019 11:37:04 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Lines: 87 Message-ID: <5c52cfce$0$498$65785112@news.neostrada.pl> Organization: Telekomunikacja Polska NNTP-Posting-Host: 95.48.160.163 X-Trace: 1548931022 unt-rea-a-02.news.neostrada.pl 498 95.48.160.163:57323 X-Complaints-To: abuse@news.neostrada.pl X-Received-Bytes: 3620 X-Received-Body-CRC: 1436689575 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit