草庐IT

element_list

全部标签

c# - List<Object> 的 XML 序列化

我无法使用XML序列化将动物列表保存到磁盘。我收到异常:抛出:“AnimalLibrary.Animals.Mammals.Dog类型不是预期的。使用XmlInclude或SoapInclude属性指定静态未知的类型。”(System.InvalidOperationException)如果我尝试使用“Dog”注释代码,它将按预期工作并生成XML。但是作为列表中唯一元素发送的同一条狗不起作用。[XmlElement("animalList")]publicListanimalList=newList();publicboolSaveBinary(stringfileName){Mamm

c# - 反序列化错误 : The XML element 'name' from namespace '' is already present in the current scope

这是我第一次使用XML序列化,在尝试解决此问题2天后,这绝对让我疯狂。反序列化开始时出现此错误:TheXMLelement'name'fromnamespace''isalreadypresentinthecurrentscope.UseXMLattributestospecifyanotherXMLnameornamespacefortheelement.错误发生在我代码中的这一行:Albumalbum=(Album)serializer.Deserialize(reader);我不知道为什么。没有重复的“名称”节点,所以我就是不明白。这是从来自第3方RESTAPI的HttpWebR

xml - xsl :sort an XML file using multiple elements

我正在尝试对XML文件中的一堆记录进行排序。诀窍是我需要对不同的节点使用不同的元素进行排序。举个最简单的例子,我想这样做:给定一个xml文件JimZulkinJoeBumpkinPumpkinAndy我想把它转换成AndyJoeBumpkinPumpkinJimZulkin也就是说,可以按名字、姓氏和昵称的任何子集列出一个人。排序键如果存在则为姓氏,如果存在则为昵称,否则为名字。我在这里遇到困难,因为使用变量作为xsl:sort键是apparentlynotallowed.我目前最好的办法是进行两步转换:使用此样式表为每条记录添加一个特殊标签然后对生成的xml进行排序虽然这种两步转换有

c# - 将作为 ICollection<> 导出的 List<> 序列化为 XML

我有一个C#.NET3.5应用程序,我想在其中序列化一个包含List的类到XML。我的类(class)看起来像这样:[XmlRoot("Foo")]classFoo{privateListbar_=newList();privatestringsomething_="MyString";[XmlElement("Something")]publicstringSomething{get{returnsomething_;}}[XmlElement("Bar")]publicICollectionBars{get{returnbar_;}}}如果我这样填充它:Barb1=newBar()

c# - 无法转换类型为 'System.Collections.Generic.List` 1 的对象

我不明白对另一种类型“System.Collections.Generic.List`1[CES.Model.SearchResult]”的引用以及如何解决此问题。Unabletocastobjectoftype'System.Collections.Generic.List`1[CES.Model.SearchResult]'totype'CES.Model.SearchResult'.Description:Anunhandledexceptionoccurredduringtheexecutionofthecurrentwebrequest.Pleasereviewthestac

c# - 使用 XElement.Elements 方法,我可以找到具有通配符命名空间但名称相同的元素吗?

尝试对XML文档进行简单的解析。拉出下面两个PropertyGroup的最简单方法是什么?12我一直在尝试使用XElement.Elements(XName),但为此我需要在PropertyGroup前加上xmlns。问题是我不关心namespace,如果将来它发生变化,我仍然希望检索所有PropertyGroup。varxml=XElement.Load(fileNameWithPath);varnameSpace=xml.GetDefaultNamespace();varpropertyGroups=xml.Elements(nameSpace+"PropertyGroup");你

xml - 架构问题 : The global element ' ' has already been declared

我遇到的问题与此处的帖子非常相似:"Globalelement'configuration'hasalreadybeendeclared"inwebconfig虽然我不清楚它的解决方案。当我打开Views下列出的web.config文件时,我也收到了大约40条警告:已声明全局元素“”。这包括配置、位置、configSections、appSettings等。我是否在某处缺少.xsd文件?当我单击“XML”选项卡和“Schemas...”选项时,它告诉我我正在使用以下.xsd:RazorCustomSchema.xsdEntityFrameworkConfig_5_0_0.xsdDotN

c# - Linq to Xml : selecting elements if an attribute value equals a node value in an IEnumerable<XElement>

我创建了一个IEnumerable对象,它只包含我想要从xml文件中获取的节点:IEnumerablerosters=XDocument.Load("roster.xml").Elements("rosterlist").Elements("roster").Where(w=>w.Element("division").Value.Equals("SUPERAWESOMEDIVISION"));所以它是这些的集合:12我只想抓取userid属性也是rosters集合中的userid节点的用户。IEnumerableusers=XDocument.Load("user.xml").Ele

xml - cvc-complex-type.2.4.a : Invalid content was found starting with element 'MarkupListURI' . 预期为 '{MarkupDeleteURI}' 之一

我一直在尝试通过验证从api到xsd的返回xml来解决这个最后的问题,在几乎所有类似的情况下,解决方案是添加以下行:elementFormDefault="qualified"然而这一行已经包含在原始xsd和子xsd中。提交的xml是:9cb5b8fe-62d8-4d52-ba32-58f1d1cc59091234172.1.1.0http://www.google.com/HELP_URIhttp://www.google.com/BRAVA_SERVER_URLKennethTest12falsehttp://www.google.com/RESOLVE_DBTOKENS_URIU

xml - XSD 验证错误 : Element '{http://www.example.com}Scope' : This element is not expected. 预期为(范围)

我创建了以下XSD(使用Eclipse):并使用这个简单的XML进行验证给出:xmllint.exe--noout--schemasources.xsdsources.xmlsources.xml:3:elementScope:Schemasvalidityerror:Element'{http://www.example.com}Scope':Thiselementisnotexpected.Expectedis(Scope).sources.xmlfailstovalidate在我看来,这必须是正确的:XML文件位于命名空间http://www.example.com中(验证者也说