Skip to content

Instantly share code, notes, and snippets.

@jclosure
Last active December 26, 2015 17:09
Show Gist options
  • Select an option

  • Save jclosure/7184666 to your computer and use it in GitHub Desktop.

Select an option

Save jclosure/7184666 to your computer and use it in GitHub Desktop.
Converts between Pascal and Camel cases for xml node names. Really just operates on the first letter of the node name.
//C#
string jStrObj =
"<?xml version='1.0' encoding='UTF-8'?><DataObject><id>ea9b96a6-1f8a-4563-9a15-b1ec0ea1bc34</id><name>blah</name><processed>false</processed></DataObject>";
//to .net style property names
string camelPattern = @"(\<(?:[a-z])|\</(?:[a-z]))";
jStrObj = Regex.Replace(jStrObj, camelPattern, m => m.Value.ToUpper());
//to java style property names
/*string pascalPattern = @"(\<(?:[A-Z])|\</(?:[A-Z]))";
jStrObj = Regex.Replace(jStrObj, pascalPattern, m => m.Value.ToLower());*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment