In Delphi 10.4.1, I use this code to reformat the XML inside a TMemo:
procedure TForm1.MyMemoFormatXML;
var
ThisXML: IXMLDocument;
begin
ThisXML := TXMLDocument.Create(nil);
ThisXML.XML.Assign(Memo1.Lines);
ThisXML.XML.Text := xmlDoc.FormatXMLData(ThisXML.XML.Text);
ThisXML.Active := True;
Memo1.Lines.Assign(ThisXML.XML);
end;
Some XML data causes an "Invalid Node type" error message when using the MyMemoFormatXML procedure, for example (XML from an SVG file):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="32px" height="32px" viewBox="0 0 32 32" enable-background="new 0 0 32 32" xml:space="preserve">
<g id="icon">
<path d="M28.4638,1.6295l0.283,6.0073c0.0116,0.2453,-0.1848,0.4505,-0.4312,0.4505h-0.0188c-0.214,0,-0.3952,-0.1573,-0.4269,-0.3683c-0.1577,-1.0518,-0.3632,-1.817,-0.6164,-2.2956c-0.4604,-0.8581,-1.0729,-1.4908,-1.8374,-1.898c-0.765,-0.4069,-1.7708,-0.5255,-3.018,-0.5255H18v22.9128c0,1.85,0.2005,2.8884,0.6014,3.3469c0.5641,0.6215,1.5768,0.9324,2.7499,0.9324h0.6348c0.2276,0,0.412,0.1839,0.412,0.4107v0c0,0.2268,-0.1845,0.4107,-0.412,0.4107H10.0593c-0.2276,0,-0.412,-0.1839,-0.412,-0.4107v0c0,-0.2268,0.1845,-0.4107,0.412,-0.4107h0.6571c1.2768,0,2.2591,-0.3847,2.7936,-1.1543c0.3264,-0.4734,0.49,-1.4379,0.49,-3.125V3h-3.7069c-1.4108,0,-2.4131,0.0188,-3.0068,0.2259c-0.7723,0.2813,-1.4331,0.8213,-1.9823,1.6205c-0.4969,0.7226,-0.8116,1.6751,-0.944,2.8573c-0.0244,0.2179,-0.2084,0.3837,-0.4284,0.3837h0c-0.2469,0,-0.4435,-0.2061,-0.4311,-0.4519l0.3019,-6.0081C3.8202,1.2759,4.1113,1,4.4644,1h23.3373C28.1556,1,28.4471,1.2771,28.4638,1.6295z" fill="#3E78B3"/>
</g>
</svg>
How can I detect the faulty node and possibly fix it?
EDIT1: Even if I use this simplified code I get the same error:
Memo1.Lines.Text := FormatXMLData(Memo1.Lines.Text);
EDIT2: GetlastError: The process was completed successfully.
EDIT3: I have found a Delphi TIDY wrapper here: https://sourceforge.net/projects/curlpas/
Unfortunately it lacks any documentation. So how can I use the included tidyobj.pas
to clean up the XML?
Using TIDY, any structural XML errors can be found and fixed:
• Test for errors in the XML/SVG file:
tidy.exe -errors -xml inputfile.xml
• Fix the errors and reformat (tidy) the XML content:
tidy.exe -q -xml inputfile.xml