XML is a flexible, convenient, way of storing data, once you understand how.
Programs typically evolve thru several versions. This often results in different data items being stored. This has meant careful tracking of data version vs program versions, as programs could not correctly read data from the wrong data version.
XML is a flexible as names are stored with the data. Names which are understood can be read, while others are ignored. The downside is that missing variables may require defaults.
XML is a very convenient to use. The rules are quite simple.
XML consists of elements:
<name> text </name>
Every opening <name> is paired with a closing </name).
Names can be almost anything but are case sensitive.
Elements can be wholly contained within other elements. <Name1> <xyz> </xyz> </Name1>
Elements cannot overlap. <Name1> <xyz> </Name1> </xyz>
The following example shows only the code to open and write a file.
sub FileSaveAs
filedialog"Save file", FilePath$+"*.Sudoku", FullName$
call GetFileName$
if FileName$=""thennotice"No file chosen!":endcall FileSave
endsubsub FileSave
open FullName$ foroutputas#File
FileOpen = True
#File "<XML>"#File "<!-- "; Date$();" "; Time$();" ";FullName$;" -->"'XML comment#File " <Sudoku>"call SaveOptions
call SaveCells
#File " </Sudoku>"#File "</XML>"close#File
FileOpen = False
notice"Puzzle Saved ";chr$(13);_
"File Name ";FileName$;chr$(13);_
"at ";FilePath$
endsubsub SaveCells
for row =1to9:for col =1to9if CellValue(row,col)<>0thencall SaveOneCell row, col, CellValue(row,col), CellStage(row,col)endifnext col:next row
endsubsub SaveOneCell row,col,value,stage
#File " <Cell>";
#File "<Row> ";row;
#File " </Row>";
#File "<Col> ";col;
#File " </Col>";
#File "<Value> ";value;
#File " </Value>";
if stage <>1then#File "<Stage> ";right$(" ";str$(stage),2);
#File " </Stage>";
else#File " ";
endif#File "</Cell>"endsubsub SaveOptions
#File " <Size> ";9;" </Size>"#File " <Diagonal>";
if DiagActive then#File " On "; else#File " Off ";
#File "</Diagonal>"#File " <Possible>";
if PossibleShow then#File " On "; else#File " Off ";
#File "</Possible>"#File " <Reduce> ";
if ReduceActive then#File " On "; else#File " Off ";
#File "</Reduce>"endsubsub GetFileName$
for pos =len(FullName$)to1 step -1ifmid$(FullName$, pos,1)="\"thenexitfornext pos
FileName$ =mid$(FullName$,pos+1)
FilePath$ =left$(FullName$,pos)endsub
XML for Data storage
XML
XML is a flexible, convenient, way of storing data, once you understand how.
Programs typically evolve thru several versions. This often results in different data items being stored. This has meant careful tracking of data version vs program versions, as programs could not correctly read data from the wrong data version.
XML is a flexible as names are stored with the data. Names which are understood can be read, while others are ignored. The downside is that missing variables may require defaults.
XML is a very convenient to use. The rules are quite simple.
XML consists of elements:
<name> text </name>
Every opening <name> is paired with a closing </name).
Names can be almost anything but are case sensitive.
Elements can be wholly contained within other elements: <Name1> <xyz> </xyz> </Name1>
Elements cannot overlap:<Name1> <xyz> </Name1> </xyz>
Reading XML data is a little more work than writting it, but still not dificult. Since you wrote the file, you only need to be able to read what you wrote.
For this example code segment, variable names with initial letters are assumed to have been declared global.
XML for Data storage
XML
XML is a flexible, convenient, way of storing data, once you understand how.Programs typically evolve thru several versions. This often results in different data items being stored. This has meant careful tracking of data version vs program versions, as programs could not correctly read data from the wrong data version.
XML is a flexible as names are stored with the data. Names which are understood can be read, while others are ignored. The downside is that missing variables may require defaults.
XML is a very convenient to use. The rules are quite simple.
XML consists of elements:
<name> text </name>
Every opening <name> is paired with a closing </name).
Names can be almost anything but are case sensitive.
Elements can be wholly contained within other elements. <Name1> <xyz> </xyz> </Name1>
Elements cannot overlap. <Name1> <xyz> </Name1> </xyz>
for more details visit: http://www.w3schools.com/xml/xml_syntax.asp
Saving Data
The following example shows only the code to open and write a file.XML for Data storage
XML
XML is a flexible, convenient, way of storing data, once you understand how.Programs typically evolve thru several versions. This often results in different data items being stored. This has meant careful tracking of data version vs program versions, as programs could not correctly read data from the wrong data version.
XML is a flexible as names are stored with the data. Names which are understood can be read, while others are ignored. The downside is that missing variables may require defaults.
XML is a very convenient to use. The rules are quite simple.
XML consists of elements:
<name> text </name>
Every opening <name> is paired with a closing </name).
Names can be almost anything but are case sensitive.
Elements can be wholly contained within other elements: <Name1> <xyz> </xyz> </Name1>
Elements cannot overlap:<Name1> <xyz> </Name1> </xyz>
for more details visit: http://www.w3schools.com/xml/xml_syntax.asp
Saving Data
The following example shows only the code to open and write a file.
Example data file:
Reading XML
Reading XML data is a little more work than writting it, but still not dificult. Since you wrote the file, you only need to be able to read what you wrote.For this example code segment, variable names with initial letters are assumed to have been declared global.