-
Notifications
You must be signed in to change notification settings - Fork 5
AcrossLite to XML
As of version 2.0, XML files (with richer content) are also created. The code looks like this:
// Get an object that can be serialized directly to XML:
Crossword crossword = puz.CrosswordObject;
// Or create an intermediate XmlDocument so you can, say, add a comment:
XmlWriterSettings settings = new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8 };
XmlWriter writer = XmlWriter.Create(xmlFilePath, settings);
XmlDocument doc = Utilities.SerializeToXmlDocument(crossword);
XmlComment xmlComment = doc.CreateComment(comment);
doc.InsertBefore(xmlComment, doc.DocumentElement);
doc.Save(writer);
Text files have a format defined by LitSoft. You can take the generated text file, open it with Across Lite, and get back the same .puz file you started with.
There is no standard for XML files. (The format here is very similar to XPF defined in XWord Info.) XML has advantages over text files:
- The data is structured, and in a common way that any computer language can parse.
- More information is available. In particular clues have numbers and answers.
- Binary indicators show whether grids have circles or rebus entries.
- Rebus elements are untangled so complete answer words are shown.
If a single .puz file is converted, the XML looks like this:
<Crossword>
<Title>NY Times, Fri, Jul 13, 2012</Title>
<Author>Jim Horne and Jeff Chen / Will Shortz</Author>
<Copyright>© 2012, The New York Times</Copyright>
<Size>
<Rows>15</Rows>
<Cols>15</Cols>
</Size>
<Grid>
<Row>..STIFLEAYAWN..</Row>
<Row>.NOHOLDSBARRED.</Row>
<Row>BUSINESSASUSUAL</Row>
...
</Grid>
<Across>
<Clue Number="1" Answer="STIFLEAYAWN">Attempt to appear alert, say</Clue>
<Clue Number="12" Answer="NOHOLDSBARRED">Unregulated</Clue>
<Clue Number="14" Answer="BUSINESSASUSUAL">The same old, same old</Clue>
...
</Across>
<Down>
<Clue Number="1" Answer="SOSAD">"My heart bleeds"</Clue>
...
</Down>
<HasCircles>false</HasCircles>
<IsRebus>false</IsRebus>
</Crossword>
If HasCircles near the bottom of the file is true, then some of the letters in the Grid will be lower-case, indicating the circle locations.
If IsRebus is true, that element will also contain one or more Codes that explain how to interpret the rebus keys (usually single-digit integers, unless there are more than 10.)
<IsRebus Codes="0:OPEL:O;1:FORD:F;2:KIA:K;3:AUDI:A">true</IsRebus>
The first part of each Code is the grid key. That's followed by the expanded rebus string. The last part is a single character that Across Lite will accept as correct if you don't bother to enter the entire rebus string.
If you convert multiple puzzles by specifying a "from" folder, separate text files are created, but all the XML gets merged into a single file:
<Crosswords>
<Crossword>
<Title>NY Times, Fri, Jul 13, 2012</Title>
<Author>Jim Horne and Jeff Chen / Will Shortz</Author>
...
</Crossword>
<Crossword>
...
</Crossword>
</Crosswords>