Children can attend a viewing. For really young children, under the age of 2, it is best to find childcare if you can. (If you must take a child this age to the visitation, be prepared to step outside quickly if the child starts crying so the mourners are not disrupted.)
For children over the age of 2, this is a judgment call you will need to make for the most part. If the visitation is for a close family member, children should go only after the parent has prepared the child for what they will see. It would also be good to discuss it with your child after attending the visitation to see if they are scared or confused by the experience.