There is a wealth of information about SGML and TEI in books, and on the Internet. Below are just some pointers to get you started:
C.M. Sperberg-McQueen and Lou Burnard:
Gentle Introduction to SGML.
In Guidelines for Electronic Text Encoding and Interchange
(C.M. Sperberg-McQueen, Lou Burnard eds.),
Chicago and Oxford, 1994.
Robin Cover:
The SGML Web Pages
the SGML newsgroup comp.text.sgml
Charles F. Goldfarb:
The SGML Handbook
Clarendon Press, Oxford, 1990.
ISBN 0-19-853737-9
C.M. Sperberg-McQueen and Lou Burnard:
Guidelines for Electronic Text Encoding and Interchange
(C.M. Sperberg-McQueen, Lou Burnard eds.),
Chicago and Oxford, 1994.
Available also at http://etext.virginia.edu/TEI.html
http://www-tei.uic.edu/orgs/tei/ (also contains 'TEI Lite: An Introduction to Text Encoding for Interchange')