Computer Chess Club Archives


Search

Terms

Messages

Subject: Replacing PGN with XML?

Author: Thorsten Greiner

Date: 08:35:48 05/29/00


Hello everybody,

PGN has become a standard for exchanging chess game data between applications
like Chessbase, X/Winboard and so on. Due to his human-readable format anyone
can read a PGN file, even without a PGN enabled tool.

But PGN has a number of drawbacks. From a developers point of view implementing
a PGN parser means a lot of 'handwork' since he cannot use a standard parsing
tool (actually you might use something like lex/yacc - but has anyone a
grammar?). From a users point of view a PGN file is 'just a set of games'. There
is no structure beyond the structure of an individual chess game, containing a
header and the moves (and annotations).

My suggestion is to develop an XML DTD for the recording of chess games. You
will find an example attached to the bottom of this posting.

Using XML would have several benefits:

o Parsing / Generation: There already are a lot of XML Parsers around which are
very easy to use. These provide parsing and verification of XML documents. Also
generation of XML documents is easy e.g. via a DOM.

o Web integration: Could be done with CSS or XSLT.

o A human readable format is still available

o Document structuring: In the example below you will find an example of an XML
DTD which structures the games by events and round. Other alternative formats
like structuring by ECO code or players are possible.

The example is only a five minute job - for the 'real thing' we should provide a
lot of additional tags (opening classification, annotations, ... are still
missing). Also representing the moves only as a #PCDATA probably is to
unstructured, so they will have to marked up, too.

WHAT DO YOU THINK?

Regards

	-Thorsten


Example XML File (actual chess data taken from TWIC 279 by Mark Crowther):

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE chess [
    <!ELEMENT chess (event*) >
    <!ELEMENT event (name, site, round*) >
    <!ELEMENT name (#PCDATA) >
    <!ELEMENT site (#PCDATA) >
    <!ELEMENT round (roundnr, game*) >
    <!ELEMENT roundnr (#PCDATA) >
    <!ELEMENT game (white, black, result, moves) >
    <!ELEMENT black (#PCDATA) >
    <!ELEMENT white (#PCDATA) >
    <!ELEMENT result (#PCDATA) >
    <!ELEMENT moves (#PCDATA) >
]>

<chess>
<event>
    <name> SuperGM </name>
    <site> Linares ESP </site>
    <round>
	<roundnr> 7 </roundnr>
	<game>
	    <white> Anand, V </white>
	    <black> Kramnik, V </black>
	    <result> 1/2-1/2 </result>
	    <moves>
		1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nf3 Nxe4 5. d4 d5
		6. Bd3 Nc6 7. O-O Be7 8. c4 Nb4 9. cxd5 Nxd3 10. Qxd3 Qxd5
		11. Re1 Bf5 12. Ne5 g6 13. f3 Nf6 14.  Qe3 O-O-O 15. Nc3 Qxd4
		16. Qxd4 Rxd4 17. Be3 Rb4 18. b3 Be6 19. Bf2 Bd6 20.  Nd3 Rd8
		21. Nxb4 Bxb4 22. Rec1 Bxc3 23. Rxc3 Nd5 24. Rd3 b6 25. Rad1
    	    </moves>
	</game>
    </round>
    <round>
	<roundnr> 8 </roundnr>
	<game>
	    <white> Khalifman, A </white>
	    <black> Leko, P </black>
	    <result> 1-0 </result>
	    <moves>
		1. d4 Nf6 2. Nf3 g6 3. c4 Bg7 4. Nc3 d5 5. cxd5 Nxd5
		6. e4 Nxc3 7. bxc3 c5 8. Rb1 O-O 9. Be2 cxd4 10. cxd4 Qa5+
		11. Bd2 Qxa2 12. O-O Bg4 13. Bg5 h6 14. Be3 Nc6 15. d5 Ne5
		16. Rxb7 e6 17. d6 Rfd8 18. Re1 Bxf3 19. gxf3 Qa5 20. Rf1 Bf8
		21. d7 Qa2 22. Bb5 a6 23. Ba4 Nxf3+ 24. Kg2 Ne5 25. Bb6 Qc4
		26.  Qd4 Qxd4 27. Bxd4 Nd3 28. Bc6 Nc5 29. Rc7 Bd6
		30. Bxc5 Bxc7 31. Bxa8 Rxa8 32. Be7 Rd8 33. Rd1 f5
		34. Bxd8 Bxd8 35. exf5 gxf5 36. Rd6 Kf7 37. Rxa6 Ke7
		38. Kg3 Bc7+ 39. Kh4 Kxd7 40. Ra7 Kc6 41. Rxc7+ Kxc7
		42. Kh5 e5 43. Kxh6 Kd6 44. Kg5 Ke6 45. h4 f4 46. h5 f3
		47. Kg4
	    </moves>
       	</game>
    </round>
</event>
</chess>



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.