本文整理汇总了C#中XmlDeserializer类的典型用法代码示例。如果您正苦于以下问题:C# XmlDeserializer类的具体用法?C# XmlDeserializer怎么用?C# XmlDeserializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlDeserializer类属于命名空间,在下文中一共展示了XmlDeserializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DeserializationWorks_WhenPassedRightXML
public void DeserializationWorks_WhenPassedRightXML()
{
var xmlPath = Path.Combine(Environment.CurrentDirectory, "SavedSearchListData.xml");
var doc = XDocument.Load(xmlPath);
var xml = new XmlDeserializer();
var output = xml.Deserialize<SavedSearchListResponseModel>(new RestResponse() { Content = doc.ToString() });
Assert.IsNotNull(output, "no deserialization worked");
Assert.IsNull(output.Errors, "deserialized errors wrong");
Assert.IsNotNull(output.SavedSearches, "SavedSearched did not Deserialize");
Assert.IsNotNull(output.SavedSearches.SavedSearchList, "SavedSearchList did not Deserialize");
//make a SavedSearchList to compare to
//this will simplify the Asserts
List<SavedSearch> searches = new List<SavedSearch>();
SavedSearch viewRetrieve = new SavedSearch();
viewRetrieve.SearchName = "viewRetrieve";
viewRetrieve.HostSite = "US";
viewRetrieve.ExternalID = "366f62b16ac491fed0ed848baa0fbc109128e67b30e75d9614d60ef1fe207d75";
searches.Add(viewRetrieve);
SavedSearch lister = new SavedSearch();
lister.SearchName = "lister";
lister.HostSite = "US";
lister.ExternalID = "67f87348bf0da271924400d9197eeba7a291c76362a9398ab1699659c60c585f";
searches.Add(lister);
Assert.AreEqual(searches[0].SearchName, output.SavedSearches.SavedSearchList[0].SearchName, "first in searchList searchname did not desearialize");
Assert.AreEqual(searches[0].HostSite, output.SavedSearches.SavedSearchList[0].HostSite, "first in searchList hostsite did not desearialize");
Assert.AreEqual(searches[0].ExternalID, output.SavedSearches.SavedSearchList[0].ExternalID, "first in searchList externalID did not desearialize");
Assert.AreEqual(searches[1].SearchName, output.SavedSearches.SavedSearchList[1].SearchName, "second in searchList searchName did not desearialize");
Assert.AreEqual(searches[1].HostSite, output.SavedSearches.SavedSearchList[1].HostSite, "second in searchList hostsite did not desearialize");
Assert.AreEqual(searches[1].ExternalID, output.SavedSearches.SavedSearchList[1].ExternalID, "second in searchList ExternalID did not desearialize");
}
开发者ID:NicholasBusby,项目名称:Careerbuilder.com-API-for-.Net,代码行数:32,代码来源:SavedSearchListTest.cs
示例2: Can_Deserialize_Attributes_Without_Matching_Case_On_Default_Root
public void Can_Deserialize_Attributes_Without_Matching_Case_On_Default_Root()
{
var doc = CreateLowercaseDashesXml();
var response = new RestResponse { Content = doc };
var d = new XmlDeserializer();
var p = d.Deserialize<PersonForXml>(response);
Assert.Equal("John Sheehan", p.Name);
Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
Assert.Equal(28, p.Age);
Assert.Equal(long.MaxValue, p.BigNumber);
Assert.Equal(99.9999m, p.Percent);
Assert.Equal(false, p.IsCool);
Assert.Equal(new Guid(GuidString), p.UniqueId);
Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
Assert.NotNull(p.Friends);
Assert.Equal(10, p.Friends.Count);
Assert.NotNull(p.BestFriend);
Assert.Equal("The Fonz", p.BestFriend.Name);
Assert.Equal(1952, p.BestFriend.Since);
Assert.NotNull(p.Foes);
Assert.Equal(5, p.Foes.Count);
Assert.Equal("Yankees", p.Foes.Team);
}
开发者ID:florinn,项目名称:RestSharp,代码行数:29,代码来源:XmlTests.cs
示例3: TestGraphWithEnumNode
public void TestGraphWithEnumNode()
{
Node rootNode = new Node(1);
Node intNode = new Node(42);
Node enumNode = new Node(TestEnum.Two);
rootNode.Nodes.Add(intNode);
rootNode.Nodes.Add(enumNode);
intNode.Nodes.Add(rootNode);
Graph g = new Graph(rootNode);
XmlSerializer s = new XmlSerializer();
string result = s.Serialize(g);
XmlDeserializer d = new XmlDeserializer();
Graph newGraph = d.Deserialize<Graph>(result);
Assert.IsNotNull(newGraph);
Assert.AreEqual(g.Root.Data, newGraph.Root.Data);
Assert.AreEqual(g.Root.Nodes[0].Data, newGraph.Root.Nodes[0].Data);
Assert.AreEqual(g.Root.Nodes[1].Data, newGraph.Root.Nodes[1].Data);
Assert.AreEqual(g.Root.Nodes[0].Nodes[0].Data, newGraph.Root.Nodes[0].Nodes[0].Data);
Assert.AreSame(newGraph.Root, newGraph.Root.Nodes[0].Nodes[0]);
}
开发者ID:joelmuzz,项目名称:DotSpatial,代码行数:26,代码来源:SerializationTests.cs
示例4: DeserializationCompiler
public DeserializationCompiler (XmlDeserializer xmlDeserializer, Type type)
: base (type)
{
if (xmlDeserializer == null) throw new ArgumentNullException ("xmlDeserializer");
this.xml_deserializer = xmlDeserializer;
}
开发者ID:pacificIT,项目名称:mono-upnp,代码行数:7,代码来源:DeserializationCompiler.cs
示例5: DeserializationWorks_WhenPassedRightXML
public void DeserializationWorks_WhenPassedRightXML()
{
//using the same XML as SavedSearchCreate since they output the same
var xmlPath = Path.Combine(Environment.CurrentDirectory, "SaveSearchCreateData.xml");
var doc = XDocument.Load(xmlPath);
var xml = new XmlDeserializer();
var output = xml.Deserialize<SavedSearchRetrieveResponseModel>(new RestResponse() { Content = doc.ToString() });
Assert.IsNotNull(output, "no deserialization worked");
Assert.IsNotNull(output.SavedSearch.SavedSearchParameters, "SavedSearchParameters deserialization Did not work");
Assert.AreEqual("lotsloc", output.SavedSearch.SearchName, "search name did not dezerialize");
Assert.AreEqual("none", output.SavedSearch.IsDailyEmail.ToLower(), "IsDailyEmail did not dezerialize");
Assert.AreEqual("Chicago, Il, Atlanta, Ga, New York, Ny", output.SavedSearch.SavedSearchParameters.Location, "Location did not dezerialize");
Assert.AreEqual(false, output.SavedSearch.SavedSearchParameters.ExcludeNational, "ExcludeNational did not dezerialize");
Assert.AreEqual("DRNS", output.SavedSearch.SavedSearchParameters.EducationCode, "educationCode did not dezerialize");
Assert.AreEqual("AND", output.SavedSearch.SavedSearchParameters.BooleanOperator, "booleanoperator did not dezerialize");
Assert.AreEqual("Pay", output.SavedSearch.SavedSearchParameters.OrderBy, "OrderBy did not dezerialize");
Assert.AreEqual(70, output.SavedSearch.SavedSearchParameters.PayHigh, "pay high did not dezerialize");
Assert.AreEqual(40, output.SavedSearch.SavedSearchParameters.PayLow, "Pay Low did not dezerialize");
Assert.AreEqual(30, output.SavedSearch.SavedSearchParameters.PostedWithin, "posted within did not dezerialize");
Assert.AreEqual(30, output.SavedSearch.SavedSearchParameters.Radius, "radius did not dezerialize");
Assert.AreEqual(false, output.SavedSearch.SavedSearchParameters.PayInfoOnly, "pay info only did not dezerialize");
Assert.AreEqual(false, output.SavedSearch.SavedSearchParameters.SpecificEducation, "specific education did not dezerialize");
Assert.AreEqual("ascending", output.SavedSearch.SavedSearchParameters.OrderDirection, "order direction did not dezerialize");
}
开发者ID:NicholasBusby,项目名称:Careerbuilder.com-API-for-.Net,代码行数:25,代码来源:SavedSearchRetrieveTest.cs
示例6: Can_Deserialize_Elements_With_Namespace
public void Can_Deserialize_Elements_With_Namespace()
{
var doc = CreateElementsXml();
var response = new RestResponse { Content = doc };
var d = new XmlDeserializer();
d.Namespace = "http://restsharp.org";
var p = d.Deserialize<PersonForXml>(response);
Assert.Equal("John Sheehan", p.Name);
Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
Assert.Equal(28, p.Age);
Assert.Equal(long.MaxValue, p.BigNumber);
Assert.Equal(99.9999m, p.Percent);
Assert.Equal(false, p.IsCool);
Assert.Equal(new Guid(GuidString), p.UniqueId);
Assert.Equal(new Uri("http://example.com", UriKind.RelativeOrAbsolute), p.Url);
Assert.Equal(new Uri("/foo/bar", UriKind.RelativeOrAbsolute), p.UrlPath);
Assert.NotNull(p.Friends);
Assert.Equal(10, p.Friends.Count);
Assert.NotNull(p.BestFriend);
Assert.Equal("The Fonz", p.BestFriend.Name);
Assert.Equal(1952, p.BestFriend.Since);
}
开发者ID:khasan,项目名称:RestSharp,代码行数:27,代码来源:NamespacedXmlTests.cs
示例7: ConvertSingle
public static object ConvertSingle(XElement xml)
{
object returnObject = null;
if (xml != null)
{
string partyType = String.Empty;
var s = new XmlDeserializer();
var element = xml.Element("type");
if (element != null)
partyType = element.Value;
if (String.IsNullOrEmpty(partyType))
{
var attribute = xml.Attribute("type");
if (attribute != null) partyType = attribute.Value;
}
switch (partyType.ToLower())
{
case "person":
returnObject = s.Deserialize<Person>(new RestResponse { Content = xml.ToString() });
break;
case "company":
returnObject = s.Deserialize<Company>(new RestResponse { Content = xml.ToString() });
break;
}
}
return returnObject;
}
开发者ID:scottschluer,项目名称:highrise-api,代码行数:31,代码来源:PartyConverter.cs
示例8: DeserializationWorks_WhenPassedRightXML
public void DeserializationWorks_WhenPassedRightXML() {
var xmlpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testdata","ResponseBlankApplication.xml");
var doc = XDocument.Load(xmlpath);
var xml = new XmlDeserializer();
var output = xml.Deserialize<BlankApplication>(new RestResponse() { Content = doc.ToString() });
Assert.IsNotNull(output.Questions);
Assert.AreEqual(4,output.Questions.Count);
Assert.AreEqual("ApplicantName", output.Questions[0].QuestionID);
Assert.AreEqual("Basic", output.Questions[0].QuestionType);
Assert.AreEqual(true, output.Questions[0].IsRequired);
Assert.AreEqual("Text 50", output.Questions[0].ExpectedResponseFormat);
Assert.AreEqual("Your name", output.Questions[0].QuestionText);
Assert.AreEqual("ApplicantEmail", output.Questions[1].QuestionID);
Assert.AreEqual("Basic", output.Questions[1].QuestionType);
Assert.AreEqual(true, output.Questions[1].IsRequired);
Assert.AreEqual("Text 50", output.Questions[1].ExpectedResponseFormat);
Assert.AreEqual("Your email", output.Questions[1].QuestionText);
Assert.AreEqual("Resume", output.Questions[2].QuestionID);
Assert.AreEqual("Basic", output.Questions[2].QuestionType);
Assert.AreEqual(true, output.Questions[2].IsRequired);
Assert.AreEqual("Text 5000", output.Questions[2].ExpectedResponseFormat);
Assert.AreEqual("Your resume", output.Questions[2].QuestionText);
Assert.AreEqual("CoverLetter", output.Questions[3].QuestionID);
Assert.AreEqual("Basic", output.Questions[3].QuestionType);
Assert.AreEqual(false, output.Questions[3].IsRequired);
Assert.AreEqual("Text 5000", output.Questions[3].ExpectedResponseFormat);
Assert.AreEqual("Your cover letter", output.Questions[3].QuestionText);
}
开发者ID:usbsnowcrash,项目名称:Careerbuilder.Net,代码行数:34,代码来源:QuestionTest.cs
示例9: Can_Deserialize_Names_With_Underscores_On_Default_Root
public void Can_Deserialize_Names_With_Underscores_On_Default_Root()
{
var doc = CreateUnderscoresXml();
var d = new XmlDeserializer();
var p = d.Deserialize<PersonForXml>(doc);
Assert.Equal("John Sheehan", p.Name);
Assert.Equal(new DateTime(2009, 9, 25, 0, 6, 1), p.StartDate);
Assert.Equal(28, p.Age);
Assert.Equal(long.MaxValue, p.BigNumber);
Assert.Equal(99.9999m, p.Percent);
Assert.Equal(false, p.IsCool);
Assert.NotNull(p.Friends);
Assert.Equal(10, p.Friends.Count);
Assert.NotNull(p.BestFriend);
Assert.Equal("The Fonz", p.BestFriend.Name);
Assert.Equal(1952, p.BestFriend.Since);
Assert.NotNull(p.Foes);
Assert.Equal(5, p.Foes.Count);
Assert.Equal("Yankees", p.Foes.Team);
}
开发者ID:CSharpByDesign,项目名称:RestSharp,代码行数:25,代码来源:XmlTests.cs
示例10: HasReceivedPlayListWith
public void HasReceivedPlayListWith(ImageId imageId)
{
ProbeFor(5000, 500, () =>
{
var request = new RestRequest
{
Resource = "playlists.xml",
RootElement = "playlists",
XmlNamespace = "",
RequestFormat = DataFormat.Xml,
Method = Method.GET
};
var response = m_Client.Execute(request);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new ApplicationException(string.Format("Unable to get playlists"));
}
var deserializer = new XmlDeserializer {Namespace = "", RootElement = ""};
var playLists = deserializer.Deserialize<RestArchive.PlayLists>(response);
Assert.That(GetImageIdsOf(playLists), Contains.Item(imageId));
});
}
开发者ID:gpad,项目名称:PlayListManager,代码行数:26,代码来源:FakeMediaServer.cs
示例11: DeserializeTest
public void DeserializeTest()
{
XmlDeserializer target = new XmlDeserializer();
DotSpatial.Controls.Map map = new DotSpatial.Controls.Map();
string path = Path.Combine("Data", "DeserializeTest.map.xml");
target.Deserialize(map, File.ReadAllText(path));
}
开发者ID:joelmuzz,项目名称:DotSpatial,代码行数:7,代码来源:XmlDeserializerTest.cs
示例12: DeserializationWorks_WhenPassedRightXML
public void DeserializationWorks_WhenPassedRightXML() {
var xmlpath = Path.Combine(Environment.CurrentDirectory,"ResponseJobSearch.xml");
var doc = XDocument.Load(xmlpath);
var xml = new XmlDeserializer();
var output = xml.Deserialize<ResponseJobSearch>(new RestResponse() { Content = doc.ToString() });
Assert.IsNotNull(output.Results);
Assert.AreEqual(25, output.Results.Count);
Assert.AreEqual("Direct Sales Recruiting, LLC", output.Results[0].Company);
Assert.AreEqual("c35x165rs82x1bnbbc", output.Results[0].CompanyDID);
Assert.AreEqual("http://www.careerbuilder.com/Jobs/Company/C35X165RS82X1BNBBC/Direct-Sales-Recruiting-LLC/?sc_cmp1=13_JobRes_ComDet", output.Results[0].CompanyDetailsURL);
Assert.AreEqual("JHM0LH6LPCGLF3FR3ZB", output.Results[0].DID);
Assert.AreEqual("41-4011.00", output.Results[0].OnetCode);
Assert.AreEqual("Full-Time", output.Results[0].EmploymentType);
Assert.AreEqual("http://api.careerbuilder.com/v1/joblink?TrackingID=DLR0T71H&DID=JHM0LH6LPCGLF3FR3ZB", output.Results[0].JobDetailsURL);
Assert.AreEqual("http://api.careerbuilder.com/v1/job?DID=JHM0LH6LPCGLF3FR3ZB&DeveloperKey=WXXXXXXXXXXXXXXXXXX", output.Results[0].JobServiceURL);
Assert.AreEqual("TN - Chattanooga", output.Results[0].Location);
Assert.AreEqual(35.04644f, output.Results[0].LocationLatitude);
Assert.AreEqual(-85.30946f, output.Results[0].LocationLongitude);
Assert.AreEqual("10/28/2012", output.Results[0].PostedDate);
Assert.AreEqual("$70k - $80k/year", output.Results[0].Pay);
Assert.AreEqual("http://www.careerbuilder.com/jobseeker/jobs/recommendedjobs.aspx?ipath=JELO&job_did=JHM0LH6LPCGLF3FR3ZB", output.Results[0].SimilarJobsURL);
Assert.AreEqual("Medical Sales-Tissue Graft/Biologics-Wound Care", output.Results[0].JobTitle);
Assert.AreEqual("http://emj.icbdr.com/MediaManagement/QS/I8F50C63D7B6SGPDXQS.gif", output.Results[0].CompanyImageURL);
Assert.IsNotNull(output.Facets);
Assert.AreEqual(0, output.Facets.Count);
}
开发者ID:NicholasBusby,项目名称:Careerbuilder.com-API-for-.Net,代码行数:28,代码来源:JobSearchResultTest.cs
示例13: DeserializeTest
public void DeserializeTest()
{
XmlDeserializer target = new XmlDeserializer();
DotSpatial.Controls.Map map = new DotSpatial.Controls.Map();
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", "DeserializeTest.map.xml");
target.Deserialize(map, File.ReadAllText(path));
}
开发者ID:DIVEROVIEDO,项目名称:DotSpatial,代码行数:7,代码来源:XmlDeserializerTest.cs
示例14: Deserialize_SerializationRepresentation_DeserializedObject
public void Deserialize_SerializationRepresentation_DeserializedObject()
{
var subject = new XmlDeserializer();
var deserialized = subject.Deserialize<Serializable>(Serializable.XmlString("s", 3m));
Assert.That(deserialized.D, Is.EqualTo(3m));
Assert.That(deserialized.S, Is.EqualTo("s"));
}
开发者ID:dgg,项目名称:testing-commons,代码行数:8,代码来源:XmlDeserializerTester.cs
示例15: Deserializer
public Deserializer (XmlDeserializer xmlDeserializer)
{
if (xmlDeserializer == null) {
throw new ArgumentNullException ("xmlDeserializer");
}
this.deserializer = xmlDeserializer;
}
开发者ID:automaters,项目名称:Mono.Upnp,代码行数:8,代码来源:Deserializer.cs
示例16: Can_Deserialize_AcoustID_Xml
public void Can_Deserialize_AcoustID_Xml()
{
var xmlpath = PathFor("AcoustID.xml");
var doc = XDocument.Load(xmlpath);
var response = new RestResponse { Content = doc.ToString() };
var d = new XmlDeserializer();
var output = d.Deserialize<MTB.Worker.AcoustID.Response>(response);
}
开发者ID:BerndK,项目名称:RestSharp,代码行数:9,代码来源:XmlTests.cs
示例17: Ignore_ReadOnly_Property_That_Exists_In_Data
public void Ignore_ReadOnly_Property_That_Exists_In_Data() {
var doc = CreateElementsXml();
var d = new XmlDeserializer();
d.Namespace = "http://restsharp.org";
var p = d.Deserialize<PersonForXml>(doc);
Assert.Null(p.ReadOnlyProxy);
}
开发者ID:restsharp,项目名称:RestSharp,代码行数:9,代码来源:NamespacedXmlTests.cs
示例18: Can_Use_DeserializeAs_Attribute_for_List
public void Can_Use_DeserializeAs_Attribute_for_List()
{
const string content =
"<document><response><oddballRootName><sid>1</sid><friendlyName>Jackson</friendlyName><oddballPropertyName>oddball</oddballPropertyName></oddballRootName></response><response><oddballRootName><sid>1</sid><friendlyName>Jackson</friendlyName><oddballPropertyName>evenball</oddballPropertyName></oddballRootName></response></document>";
var xml = new XmlDeserializer();
List<Oddball> output = xml.Deserialize<List<Oddball>>(new RestResponse { Content = content });
Assert.NotNull(output);
Assert.AreEqual("1", output[0].Sid);
}
开发者ID:xw616525957,项目名称:RestSharp,代码行数:10,代码来源:XmlDeserializerTests.cs
示例19: ZoomToMaxExtentTest
public void ZoomToMaxExtentTest()
{
XmlDeserializer target = new XmlDeserializer();
Map map = new Map();
string path = Path.Combine("TestFiles", "testproject1.dspx");
target.Deserialize(map, File.ReadAllText(path));
map.ZoomToMaxExtent();
}
开发者ID:joelmuzz,项目名称:DotSpatial,代码行数:10,代码来源:MapTest.cs
示例20: Can_Use_DeserializeAs_Attribute_for_List
public void Can_Use_DeserializeAs_Attribute_for_List()
{
string xmlpath = this.PathFor("deserialize_as_list.xml");
XDocument doc = XDocument.Load(xmlpath);
XmlDeserializer xml = new XmlDeserializer();
List<Oddball> output = xml.Deserialize<List<Oddball>>(new RestResponse { Content = doc.ToString() });
Assert.NotNull(output);
Assert.AreEqual("1", output[0].Sid);
}
开发者ID:CL0SeY,项目名称:RestSharp,代码行数:10,代码来源:XmlDeserializerTests.cs
注:本文中的XmlDeserializer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论