Marth is one of the trickest characters to edgeguard if he still has his midair jump, and it's something that even Hax has trouble against. Unsweet-spotted recoveries have already been covered here, so I'll talk about sweet-spotted recoveries.
If you're on the ledge and roll onto the stage too early, then Marth can just stall with his second jump and sweet spot the ledge after the edgehog period is over. In this case, do what krazyzyko said: grab the ledge right before his Dolphin Slash can hit you, and use that invincibility to shinespike him. You're not going to be able to edgeguard sweetspotted Dolphin Slash from the stage by conventional means, because his disjoint hitbox will reach through your DSmash's lower invincibility and still hit you.
If he stalls with his midair jump, then just tap your control stick to get onto the stage normally without rolling and get ready to light shield. If he Dolphin Slashes you to try and hit you away, then you can punish him out of shield. If he goes for a sweetspot, then tilt your lightshield to the ledge and edgehog him.
Ideally, however, you want to grab the ledge as late as you can against Marth while it's still safe so that you don't get stage spiked. Use those invincibility frames to drop down and shine or do a rising Bair from under him if he's slightly too far away. Use judgement, and don't overexert to the point that he can hit you out of your invincibility frames. Additionally, you can stall on the ledge with Firefox (tap away and quickly up+B), but you only have one frame to do it perfectly. The slower you are, the more frames you'll be vulnerable on.