A study of the fragmentation properties of charm and bottom quarks into D mesons is presented. From 263 700 Z0 hadronic decays collected in 1991 with the DELPHI detector at the LEP collider, D0, D+ and D*+ are reconstructed in the modes K- pi+, K- pi+pi+ and D0pi+ followed by D0-->K- pi+, respectively. The fractional decay widths GAMMA(Z0-->D/DXBAR)/GAMMA(h) are determined, and first results are presented for the production of D mesons from ccBAR and bbBAR events separately. The average energy fraction of D*+/- in charm quark fragmentation is found to be [X(E)(D*)]c=0.487+/-0.015 (stat)+/-0.005 (sys.). Assuming that the fraction of D(s) and charm-baryons produced at LEP is similar to that around 10 GeV, the Z0 partial width into charm quark pairs is determined to be GAMMA(c)/GAMMA(h)=0.187+/-0.031 (stat)+/-0.023 (sys). The probability for a b quark to fragment into B(s)BAR or b-baryons is inferred to be 0.268+/-0.094 (stat)+/-0.100 (sys) from the measured probability that it fragments into a B0BAR or B-.