Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

di241253134

@di241253134
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • C# xml serialization
    D di241253134

    I have this class User:

    \[Serializable()\]
    \[XmlRoot("Users")\]
    public class Users
    {
        \[XmlArrayItem(typeof(User))\]
        public List UsersList { get; set; }
    }
    
    
    \[Serializable()\]
    public class User
    {
        \[System.Xml.Serialization.XmlAttribute("ID")\]
        public string ID { get; set; }
    
        \[System.Xml.Serialization.XmlElementAttribute("Name")\]
        public string Name { get; set; }
    
        \[System.Xml.Serialization.XmlElementAttribute("Username")\]
        public string Username { get; set; }
    
        \[System.Xml.Serialization.XmlElementAttribute("Password")\]
        public string Password { get; set; }
    
        \[System.Xml.Serialization.XmlElementAttribute("Email")\]
        public string Email { get; set; } = string.Empty;
    }
    

    And this:
    private void Serialization()
    {
    var path = @"D:\Projects\repo\xml\users.xml";
    var newUsers = new Users();
    newUsers.UsersList = new List();

                var user = new User
                ();
                user.Email = txtEmail.Text;
                user.Name = txtName.Text;
                user.Password = txtPass.Text;
                user.ID =txtID.Text;
                newUsers.UsersList.Add(user);
    
            XmlSerializer serializer = new XmlSerializer(typeof(Users));
            using (TextWriter writer =  new StreamWriter(path,true))
            {
                serializer.Serialize(writer, newUsers);
            }
        }
    

    And it saves this xml:

    		a
    		a
    		a
    	
    
    
    	
    		s
    		s
    		ss
    

    But I want to save the xml file in this format:

    		a
    		a
    		a
    	
    	
    		s
    		s
    
    C# csharp xml json
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups