The reason your example is failing is because the constructor for XAttribute expects the name of the attribute and its value.
So with new XElement("SubstitutionAttribute", new XAttribute("SubNetwork Group",subNetBox.Text)) you are acutally declaring only one attribute with the name "Subnetwork Group" and the value subNetBox.Text (<SubstitutionAttribute SubNetwork Group="Something" />). This is invalid XML as you can't have spaces in an attribute name.
What I think you are trying to do should be done with two attributes - one called name and the other called value:
new XElement("SubstitutionAttribute",
new XAttribute("name", "SubNetwork Group"),
new XAttribute("value", subNetBox.Text));