🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.delphi
1 messages
1 total messages Started by konsul41 Thu, 31 Jan 2019 10:37
Jak sprawdzacie poprawność xlm względem XSD
#346924
Author: konsul41
Date: Thu, 31 Jan 2019 10:37
86 lines
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/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads