Revert "Revert "Prevent NRE when x.Attribute returns null""

This reverts commit 203e535f5f70c96f0e8b2bf0cf8830b01b938c9b.