Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have two class foo and wrappers
foo is my original class and i create a list from foo class
and wrappers class decorate with [serializable] and [xmlelement(ElementName=)]

this is my foo class
public class foo
 {
     public string Name { get; set; }
     public string Family { get; set; }
     public int ID { get; set; }

 }


and this is my wrappers class
[Serializable]
   public class wrappers
   {
       [XmlElement(ElementName = "FirstName")]
       public string Name { get; set; }
       [XmlElement(ElementName = "LastName")]
       public string Family { get; set; }
       [XmlElement(ElementName = "BranchCode")]
       public int ID { get; set; }
   }

when i use decorate like above custome xml is
<?xml version="1.0"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wrappers>
    <FirstName>Ali</FirstName>
    <LastName>Shahmohammadi</LastName>
    <BranchCode>1</BranchCode>
  </wrappers>
  <wrappers>
    <FirstName>Hossein</FirstName>
    <LastName>Shahmohammadi</LastName>
    <BranchCode>2</BranchCode>
  </wrappers>
</Root>


but when i use decorate like this for wrappers class
[Serializable]
   public class wrappers
   {
       [XmlElement(ElementName = "101")]
       public string Name { get; set; }
       [XmlElement(ElementName = "102")]
       public string Family { get; set; }
       [XmlElement(ElementName = "103")]
       public int ID { get; set; }
   }

custome xml tag is not currrect display and custome xml tag is
<?xml version="1.0"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wrappers>
    <_x0031_01>Ali</_x0031_01>
    <_x0031_02>Shahmohammadi</_x0031_02>
    <_x0031_03>1</_x0031_03>
  </wrappers>
  <wrappers>
    <_x0031_01>Hossein</_x0031_01>
    <_x0031_02>Shahmohammadi</_x0031_02>
    <_x0031_03>2</_x0031_03>
  </wrappers>
</Root>

and i want have custome xml like
<?xml version="1.0"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wrappers>
    <101>Ali</101>
    <102>Shahmohammadi</102>
    <103>1</103>
  </wrappers>
  <wrappers>
    <101>Hossein</101>
    <102>Shahmohammadi</102>
    <103>2</103>
  </wrappers>
</Root>


What I have tried:

to create xml and use it on my application
Posted
Updated 24-Feb-17 1:09am
v2

1 solution

What you want doesn't seem to be too standard, XML explicitly disallows numbers (and some other things) as the first character of an element name:
NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] |
                  [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] |
                  [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] |
                  [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] |
                  [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900