Is there a way for Lazarus Free Pascal to check if a XML Code is well formed without using a DTD?
A DTD is really specific but i just want to check if the Syntax is right.
Is there a way for Lazarus Free Pascal to check if a XML Code is well formed without using a DTD?
A DTD is really specific but i just want to check if the Syntax is right.
Thank you for your help, i found something here https://wiki.lazarus.freepascal.org/XML_Tutorial/de but i wasnt sure if i need a DTD.
uses XMLRead,DOM;
procedure TXML.XMLValidate(input : string);
//https://wiki.lazarus.freepascal.org/XML_Tutorial/de
var
Parser: TDOMParser;
Src: TXMLInputSource;
TheDoc: TXMLDocument;
begin
// Create new ParseObject
Parser := TDOMParser.Create;
try
// Load the XML in a TXMLInputSource
Src := TXMLInputSource.Create(input);
try
// Check structure
Parser.Options.Validate := True;
// You can call a Method for an Error if needed
//Parser.OnError := ErrorHandler;
// This is the check, we get an exception if the Syntax is not true
try
Parser.Parse(Src, TheDoc);
Error := false;
except
Error := true;
end;
// ... and clean
finally
Src.Free;
end;
finally
Parser.Free;
end;
end;