Not easy and I would not add anything to what everyone wrote above, although I do want to put out a few different scenarios that may be options to help make things more comfortable, depending on the formalities of the funeral.
If there's prayers, that might be an option to go and sit in a back row away from the rest of the family and possibly OW. The kids could go up for viewing and to give their respects. That is also possible the day of the funeral service, prior to burial or interment.
If going on day of funeral service, you could take the kids and they could possible go with their dad to burial or interment and you stay back.
If a wake or similar, you could always drop the kids off and pick them up. Obviously, if you are not invited, you would not go in, if you are invited, you'd make that choice.
Of course, in situations like this it is good for us to put aside personal issues. Something else for you specifically would be to find out who is going that is a friend and neutral party in your sitch with XH and stick with them during the prayers, service, interment, wake, etc.