SHARE
TWEET

Untitled

a guest Jun 26th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Ref1 Att11="XXX" Att21="YYY" Att31="ZZZ">
  3.  <Ref2 Att12="AAA" Att22="BBB" Att32="CCC">
  4.  <Ref3 Att13="111" Att23="222" Att33="333"/>
  5.  </Ref2>
  6. </Ref1>
  7.      
  8. public class Ref1
  9. {
  10.     public string Att11 { get; set; }
  11.     public string Att21 { get; set; }
  12.     public string Att31 { get; set; }
  13.  
  14.     public List<Ref2> ref2;
  15. }
  16.  
  17. public class Ref2
  18. {
  19.     public string Att12 { get; set; }
  20.     public string Att22 { get; set; }
  21.     public string Att32 { get; set; }
  22.  
  23.     public Ref3 ref3;
  24. }
  25.  
  26. public class Ref3
  27. {
  28.     public string Att13 { get; set; }
  29.     public string Att23 { get; set; }
  30.     public string Att33 { get; set; }
  31. }
  32.      
  33. using System;
  34. using System.Collections.Generic;
  35. using System.Linq;
  36. using System.Text;
  37. using System.Xml;
  38. using System.Xml.Serialization;
  39.  
  40. namespace ConsoleApplication1
  41. {
  42.     class Program
  43.     {
  44.         const string INPUT_FILENAME = @"c:temptest.xml";
  45.         const string OUTPUT_FILENAME = @"c:temptest1.xml";
  46.         static void Main(string[] args)
  47.         {
  48.             XmlReaderSettings rSettings = new XmlReaderSettings();
  49.             rSettings.Schemas = null;
  50.             XmlReader reader = XmlReader.Create(INPUT_FILENAME, rSettings);
  51.             XmlSerializer serializer = new XmlSerializer(typeof(Ref1), string.Empty);
  52.  
  53.             Ref1 ref1 = (Ref1)serializer.Deserialize(reader );
  54.  
  55.  
  56.             XmlWriterSettings wSettings = new XmlWriterSettings();
  57.             wSettings.Indent = true;
  58.             XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
  59.             namespaces.Add("","");
  60.             XmlWriter writer = XmlWriter.Create(OUTPUT_FILENAME, wSettings);
  61.             serializer.Serialize(writer, ref1, namespaces);
  62.         }
  63.     }
  64.     public class Ref1
  65.     {
  66.         [XmlAttribute("Att11")]
  67.         public string Att11 { get; set; }
  68.         [XmlAttribute("Att21")]
  69.         public string Att21 { get; set; }
  70.         [XmlAttribute("Att31")]
  71.         public string Att31 { get; set; }
  72.         [XmlElement("Ref2")]
  73.         public List<Ref2> ref2;
  74.     }
  75.  
  76.     public class Ref2
  77.     {
  78.         [XmlAttribute("Att12")]
  79.         public string Att12 { get; set; }
  80.         [XmlAttribute("Att22")]
  81.         public string Att22 { get; set; }
  82.         [XmlAttribute("Att32")]
  83.         public string Att32 { get; set; }
  84.  
  85.         [XmlElement("Ref3")]
  86.         public Ref3 ref3;
  87.     }
  88.  
  89.     public class Ref3
  90.     {
  91.         [XmlAttribute("Att13")]
  92.         public string Att13 { get; set; }
  93.         [XmlAttribute("Att23")]
  94.         public string Att23 { get; set; }
  95.         [XmlAttribute("Att33")]
  96.         public string Att33 { get; set; }
  97.     }
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top