当前位置: 首页>>代码示例>>C#>>正文


C# XmlDocument.Deserialize方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.Deserialize方法的具体用法?C# XmlDocument.Deserialize怎么用?C# XmlDocument.Deserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.Deserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestXmlDocumentSeiralization

        public void TestXmlDocumentSeiralization()
        {
            var objTree = new ObjectTree
            {
                Foo = "Foo1",
                Bar = 1,
                Nested = new List<object>()
            };

            objTree.Nested.AddRange(new[]
                {
                    new ObjectTree{ Foo = "Foo2", Bar = 2},
                    new ObjectTree{ Foo = "Foo3", Bar = 3},
                });

            XmlDocument xmlDoc = objTree.ToXmlDocument();
            string xml = xmlDoc.ToXml();
            Assert.IsNotNull(xml);

            XmlNode parentElem = xmlDoc.DocumentElement;
            objTree.SerializeInto(parentElem);

            xml = xmlDoc.ToXml();
            Assert.IsNotNull(xml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xml);
            ObjectTree newObjectTree = xmlDoc.Deserialize<ObjectTree>();
            Assert.IsNotNull(newObjectTree);

            ObjectTree nested = newObjectTree.AnyXml.Deserialize<ObjectTree>();
            Assert.AreEqual(1, nested.Bar);
            Assert.AreEqual(objTree.Nested.Count, nested.Nested.Count);
        }
开发者ID:vgribok,项目名称:Aspectacular,代码行数:34,代码来源:XmlSerializationTest.cs

示例2: Load

		public static LoggerConfig Load(string xmlFilePath = null) {
			if (xmlFilePath == null) {
				xmlFilePath = c_xmlFilePath;
			}
			var doc = new XmlDocument();
			doc.Load(xmlFilePath);
			var nav = doc.CreateNavigator();
			var ns = nav.GetNamespacesInScope(new XmlNamespaceScope());
			return doc.Deserialize<LoggerConfig>();
		}
开发者ID:zzilla,项目名称:ONVIF-Device-Manager,代码行数:10,代码来源:LoggerConig.cs

示例3: Load

        public void Load(string levelName)
        {
            if (levelName.StartsWith("JAFM_WORKAROUND_SAVE:")) {
                string[] split = levelName.Split(new char[] {':'});
                Save(split[1], (split.Length > 2) ? bool.Parse(split[2]) : false);
                return;
            }
            if (levelName == "JAFM_WORKAROUND_CHANGELEVEL") {
                ChangeLevel(GameLevelManagerHelper.ChangeLevel_);
                return;
            }

            if (tmpLevel != null) {
                ClearArtSatellites();

                oldLevel = levelData;
                levelData = tmpLevel;
                tmpLevel = null;

                levelData.OnDeserialization();
                return;
            }

            levelName = FEZMod.ProcessLevelName(levelName);

            string filePath_ = ("Resources\\levels\\"+(levelName.ToLower())).Replace("\\", Path.DirectorySeparatorChar.ToString()).Replace("/", Path.DirectorySeparatorChar.ToString())+".";

            string filePathFMB = filePath_ + "fmb";
            FileInfo fileFMB = new FileInfo(filePathFMB);
            if (fileFMB.Exists) {
                ModLogger.Log("FEZMod", "Loading level from FMB: "+levelName);

                using (FileStream fs = new FileStream(fileFMB.FullName, FileMode.Open)) {
                    throw new FormatException("FEZMod can't load FMB files yet.");
                }

                return;
            }

            string filePathXML = filePath_+"xml";
            FileInfo fileXML = new FileInfo(filePathXML);
            if (!fileXML.Exists) {
                if (MemoryContentManager.AssetExists("LEVELS/"+levelName)) {
                    orig_Load(levelName);
                } else {
                    //Fallback: Spawn at the original VILLAGEVILLE_3D if the level wasn't found at all
                    ModLogger.Log("FEZMod", "Level not found: " + levelName + "; Falling back to the original VILLAGEVILLE_3D...");
                    orig_Load("VILLAGEVILLE_3D");
                }
                FEZMod.ProcessLevelData(levelData);
                GameLevelManagerHelper.Level = levelData;
                return;
            }

            ModLogger.Log("FEZMod", "Loading level from XML: "+levelName);

            ClearArtSatellites();

            oldLevel = levelData;

            FileStream fis = new FileStream(fileXML.FullName, FileMode.Open);
            XmlReader xmlReader = XmlReader.Create(fis);
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(xmlReader);
            xmlReader.Close();
            fis.Close();

            ContentManager cm = CMProvider.GetForLevel(levelName);
            levelData = (Level) xmlDocument.Deserialize(null, cm, true);
            levelData.Name = levelName;

            LevelSaveData save = GameState.SaveData.ThisLevel;
            if (save != null) {
                save.FirstVisit = false;
            }

            FEZMod.ProcessLevelData(levelData);
            GameLevelManagerHelper.Level = levelData;
        }
开发者ID:Gyoo,项目名称:FEZMod,代码行数:79,代码来源:GameLevelManager.cs

示例4: ToXML2

 public void ToXML2()
 {
     Assert.NotNull(TestItem.Serialize(new XMLSerializer(), FileLocation: @".\Testing\Test.xml"));
     XmlDocument Document = new XmlDocument();
     Document.LoadXml(new FileInfo(@".\Testing\Test.xml").Read());
     TestClass Temp = Document.Deserialize<TestClass>(new XMLSerializer());
     Assert.Equal(123, Temp.ID);
     Assert.Equal("This is test content", Temp.Content);
 }
开发者ID:rgshare,项目名称:Craig-s-Utility-Library,代码行数:9,代码来源:Serialization.cs


注:本文中的System.Xml.XmlDocument.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。