How can I check if a xml file is well formed without invalid chars or tags?
For example, consider this xml:
How are you creating/receiving the XML? Any sensible parser would catch this.
For example, using OmniXML
uses
OmniXML;
type
TForm1=class(TForm)
Memo1: TMemo;
//...
private
FXMLDoc: IXMLDocument;
procedure FormCreate(Sender: TObject);
procedure CheckXML;
end;
implementation
uses
OmniXMLUtils;
procedure TForm1.FormCreate(Sender: TObject);
begin
// Load your sample XML. Can also do Memo1.Text := YourXML
Memo1.Lines.LoadFromFile('YourXMLFile.xml');
end;
procedure TForm1.CheckXML;
begin
FXMLDoc := CreateXMLDoc;
// The next line raises an exception with your sample file.
XMLLoadFromAnsiString(FXMLDoc, Memo1.Text);
end;