Illegal XML Tag Name Characters can be encoded using Unicode UCS-2. This works very nicely. I am using it to create XML that gets turned into json (JPath is weak compared to XPath). Notice the handling of spaces, (, ) characters. Unicode UCS-2 Code Chart: http://www.columbia.edu/kermit/ucs2.html
tag.Name = tag.Name.Replace(" ", "_x005F_x0020_");
tag.Name = tag.Name.Replace("(", "_x005F_x0028_");
tag.Name = tag.Name.Replace(")", "_x005F_x0029_");
XML:
<Internal_x005F_x0020_Chargeback_x005F_x0020_ID>{CHARGEBACKCODE}</Internal_x005F_x0020_Chargeback_x005F_x0020_ID>
<Bill_x005F_x0020_To>{CHARGEBACKCODE}</Bill_x005F_x0020_To>
<Operator_x005F_x0020_or_x005F_x0020_Directly_x005F_x0020_Responsible_x005F_x0020_Individual_x005F_x0020__x005F_x0028_DRI_x005F_x0029_>[email protected]</Operator_x005F_x0020_or_x005F_x0020_Directly_x005F_x0020_Responsible_x005F_x0020_Individual_x005F_x0020__x005F_x0028_DRI_x005F_x0029_>
transformed to json via json.net:
"Internal Chargeback ID": "{CHARGEBACKCODE}",
"Bill To": "{CHARGEBACKCODE}",
"Operator or Directly Responsible Individual (DRI)": "[email protected]",