Generate C# class from XML

Generate C# class from XML

Asked on December 18, 2018 in XML.
Add Comment


  • 3 Answer(s)

    Generate C# class from XML:

    D:\temp>xsd test.xml
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 4.0.30319.1]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file 'D:\temp\test.xsd'.
     
    D:\temp>xsd test.xsd /classes
    Microsoft (R) Xml Schemas/DataTypes support utility
    [Microsoft (R) .NET Framework, Version 4.0.30319.1]
    Copyright (C) Microsoft Corporation. All rights reserved.
    Writing file 'D:\temp\test.cs'.
    

         If the classes are generated for multi-dimensional array,follow the bug in XSD.exe generator

    Answered on December 18, 2018.
    Add Comment

    Explanation for C# from XML:

         While working on .NET 4.5 project in VS 2012 or new, just Special Paste the XML file as classes.

    • Copy XML file’s content to clipboard
    • In editor, select place where need the classes to be pasted
    • From the menu, select EDIT > Paste Special > Paste XML As Classes

     

    Answered on December 18, 2018.
    Add Comment

    Follow this answer:

         The segment which generates are given below,

    namespace Xml2CSharp
    {
      [XmlRoot(ElementName="entry")]
      public class Entry {
        [XmlElement(ElementName="hybrisEntryID")]
        public string HybrisEntryID { get; set; }
        [XmlElement(ElementName="mapicsLineSequenceNumber")]
        public string MapicsLineSequenceNumber { get; set; }
    
    Answered on December 18, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.