.

creating CS classes from XML or XSD

Open the Visual Studio Command Prompt (Start -> Visual Studio -> Visual Studio Tools -> Visual Studio Command Prompt).

Navigate to your folder containing the XML/XSD file, e.g.:
cd “c:\temp”

Type:
xsd xmlFileToConvert.xml

this will creat a .xsd file in the same folder

Type:
xsd xmlFileToConvert.xsd /classes

this will creat a .cs file in the same folder

To Deserialize this file:

public void decode(string input)
{
    var ContentFromXmlFile = XmlDeserialize<OuterClassName>(input);
}

public T XmlDeserialize<T>(string xml)
{
    var textReader = new XmlTextReader(new StringReader(xml));
    var xmlSerializer = new XmlSerializer(typeof (T)); 
    var result = xmlSerializer.Deserialize(textReader);
    return (T) result;
}

2 Responses to this post.

  1. Posted by pietman on 22.08.13 at 9:24 pm

  2. Posted by pietman on 22.08.13 at 9:24 pm

    var obj = JObject.Parse(“{’123456′: ‘help’}”);
    var str = obj["123456"];

What's your thoughts on this?

*

Protected by WP Anti Spam