prettifying XML output
lazarus / 21-General
----------------------------------------------------------------------
indydev · 2021-09-08 23:25
I am able to successfully put out this XML scheme sheet, but would
like to space out some of this output.
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Color Me
<_description>Color Scheme using New-Color color
palatte
Like this:
Code: XML [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i Color Me
<_description>Color Scheme using New-Color color
palatte
So both vertical space between some nodes, and some tab lining up with
the attributes. The SetAttribute function does not allow for spaces
before the first character, and no 'tabs' [i.e. #9 ] or other
characters in them. Do I need to just write it out and open it as a
regular text file and fix it that way?
----------------------------------------------------------------------
BobDog · 2021-09-10 22:11
Save the file as tst1.xml in a folder.
Put in the path to the folder (line 69 ish), (and not use my path of
course)
The new file is tst2.xml, with a custom change.
Code: Pascal [Select][+][-]window.onload = function(){var x1 =
document.getElementById("main_content_section"); if (x1) { var x =
document.getElementsByClassName("geshi");for (var i = 0; i program
customfilechange; uses sysutils; typeaos=array of ansistring;
procedure savefile(s:ansistring ;filename:ansistring); var
f:textfile; begin AssignFile(f,filename);
Rewrite(f); writeln(f,s); closefile(f);
end; function loadfile(filename:ansistring; var s:ansistring):aos;
var ret:ansistring; f:textfile; counter:integer; a:aos;
begin if (fileexists(filename)=false) then begin s:='';
writeln(filename,' not found'); exit(nil); end;
setlength(a,0); counter:=0; s:=''; AssignFile(f,filename);
reset(f); while not eof(f) do begin counter:=counter+1;
readln(f, ret); s:=s+ret+#13#10; end;
setlength(a,counter); reset(f); counter:=0; while not eof(f)
do begin readln(f, a[counter]); counter:=counter+1;
end; CloseFile(f); exit(a); end; {loadfile} procedure
fillstring(a:aos;var s:ansistring); var i:int32; begin s:='';
for i:=low(a) to high(a) do s:=s+a[i]+#13#10; end; var a:aos;
var FolderPath,ans,blank,head,tail:ansistring; var i,n:int32;
begin
FolderPath:='C:\Users\Computer\Desktop\fb\pascal\mystuff\';
a:=loadfile(FolderPath+'tst.xml',ans); writeln('Original');
writeln(ans); writeln; for i:=low(a) to high(a) do
begin if (pos('-->',a[i])<>0) then a[i]:= #10+a[i]; if
(pos('" ',a[i]) <> 0) and (i>4) then begin n:= pos('"
',a[i]); Setlength(blank,40-n);
FillChar(blank[1],length(blank),' '); head:=a[i][1 .. n];
tail:= copy(a[i],n+1,length(a[i])); a[i]:=head+blank+tail;
end; end; fillstring(a,ans); writeln('saving file');
writeln; savefile(ans,FolderPath+'tst2.xml'); ans:='';
loadfile( FolderPath+'tst2.xml',ans); writeln('File content:');
writeln(ans); readln; end. That's about all I can do here.
----------------------------------------------------------------------
indydev · 2021-09-11 19:25
Thanks! Given the dearth of responses and your example, I guess the
answer to my question is "yes" use a textfile process. I started
something similar already using StringList and pos, but yours is more
complete. I am now thinking I might skip the whole XMLWrite process
and just hard code much of the output and send it out as a textfile
since this is fairly simple, and not a general XML creator.
Thanks again.