The chemical reactions and pathways involving xylan, a polymer containing a beta-1,4-linked D-xylose backbone.