linq-to-xml

Is it possible to load a UserControl into an anonymous object, instead of just instantiating it?

笑着哭i 提交于 2019-12-24 23:31:11
问题 Currently I'm generating UserControls as follows in an abstract base class so they are available for any other pages that implement the base class: // doc is an XML file that may or may not contain a TopStrapline node var pageControls = new { TopStrapline = (from strap in doc.Elements("TopStrapline") select new TopStrapline { StraplineText = (string)strap.Attribute("text") }).FirstOrDefault(), // loads of other UserControls generated from other nodes }; // if there's a StrapLine node, I want

A Better XElement to Object Without XMLAttributes in C#

落花浮王杯 提交于 2019-12-24 21:05:28
问题 Given an XElement input: <?xml version="1.0"?> <Item Number="100" ItemName="TestName1" ItemId="1"/> with an Item model like: public class Item { public int ItemId { get; set; } public string ItemName { get; set; } public int? Number { get; set; } // public DateTime? Created {get; set;} } Why does this code: public static T DeserializeObject<T>(XElement element) where T : class, new() { try { var serializer = new XmlSerializer(typeof(T)); var x = (T)serializer.Deserialize(element.CreateReader(

Query Collection of all XML Elements

北慕城南 提交于 2019-12-24 20:01:51
问题 I'm looking to parse an XML file, and have the ability to search any element. My XML code looks rather nontraditional (out of my control): <DiagReport> <LicensingData> <ToolVersion>6.3.9431.0</ToolVersion> <LicensingStatus>SL_LICENSING</LicensingStatus> </LicensingData> <Health> <Result>PASS</Result> <TamperedItems></TamperedItems> </Health> <Genuine> <ServerProps>GenuineId</ServerProps> </Genuine> </DiagReport> I'd like to load each singular element into a collection, i.e. one collection

Repository pattern - Switch out the database and switch in XML files

爷,独闯天下 提交于 2019-12-24 19:09:38
问题 Repository pattern - Switch out the database and switch in XML files. Hello I have an asp.net MVC 2.0 project and I have followed the Repository pattern. Periodically, I am losing access to the database server so I want to have another mechanism in place (XML files) to continue developing. It is not possible to have a local version of the db unfortunately! I thought this would be relatively easy using the Repository pattern, to switch out the db repositories and switch in XML versions.

creating XML file with LINQ to XML

安稳与你 提交于 2019-12-24 19:07:55
问题 I need to write linq to xml query of such kind of below xml data <PRODUCT> <ID>34169</ID> <D1>good</D1> <D2>well</D2> <L1>lame</L1> <L2>killer</L2> <BR>IOMEGA</BR> <KDV>18</KDV> <IMG>34169.JPG</IMG> <EAN>data1</EAN> <ATP>50+</ATP> <DM3>0,51</DM3> <S> <L>Tip</L> <V>HARICI</V> </S> <S> <L>Renk</L> <V>METALIK GRI</V> </S> <S> <L>Kapasite (GB)</L> <V>500</V> </S> <S> <L>Dönüş Hızı (Rpm)</L> <V>5400,0</V> </S> <S> <L>Arabirim</L> <V>USB 2.0</V> </S> <S> <L>Form Faktörü (Inch)</L> <V>2,5</V> </S>

How do you use linq to xml to find matching nodes in two different xml files

左心房为你撑大大i 提交于 2019-12-24 19:07:46
问题 I just asked another question here and the answer was spot on. But that addressed what was essentially a syntax problem. Now I need help with an actual resolution. This is the same code from the previou question (fixed up and with stuff added). XElement FILE1 = XElement.Load (@"..\FILE1.XML"); XElement FILE2 = XElement.Load (@"..\FILE2.XML"); var orders = from file1 in FILE1.Descendants("Players").Elements("Player") select new { name=new { clientID=ulm.Element("ClientID").Value, firstName

put xml into Array

那年仲夏 提交于 2019-12-24 17:09:33
问题 I have an xml file, and I need to be able to sort it in either a list or an array The XML: <Restaurant> <name>test</name> <location>test</location> </Restaurant> <Restaurant> <name>test2</name> <location>test2</location> </Restaurant> All the Restaurants will have the same number of fields and the same names for the fields, but the number of <Restaurant></Restaurant> in a given xml file is unknown. In other words, I need an array or list and be able to do this: String name = restaurantArray[0

How to find XmlNodes based on a child elements name and value

核能气质少年 提交于 2019-12-24 13:53:03
问题 Im having trouble getting a XmlNodeList where there is 1 child with a specific name that <tables> <table tableName="Orders"> <item table="Orders"> ... </item> <item table="Orders"> ... </item> </table> <table tableName="OrderWithParent"> <item table="OrderWithParent"> <column columnName="OrderWithParentId"><![CDATA[156]]></column> <column columnName="OrderParentId"><![CDATA[1]]></column> ... </item> <item table="OrderWithParent"> <column columnName="OrderWithParentId"><![CDATA[156]]></column>

Parse XML linq namespace issue

匆匆过客 提交于 2019-12-24 13:46:59
问题 Follwoing the XML I am parsing using Linq to XML. Using below code but getting nothing. <?xml version="1.0" encoding="utf-8"?> <!--ADOR Acknowledgement 2--> <AckTransmission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.irs.gov/efile"> <TransmissionHeader recordCount="1"> <Jurisdiction>ALABAMA</Jurisdiction> <TransmissionId>1946157056</TransmissionId> <Timestamp>2012-08-16T01:25:47-05:00</Timestamp> <Transmitter> <ETIN>00000</ETIN> </Transmitter> <ProcessType>T<

Xml gets corrupted each time I append a node

风格不统一 提交于 2019-12-24 13:43:10
问题 I have an Xml file as: <?xml version="1.0"?> <hashnotes> <hashtags> <hashtag>#birthday</hashtag> <hashtag>#meeting</hashtag> <hashtag>#anniversary</hashtag> </hashtags> <lastid>0</lastid> <Settings> <Font>Arial</Font> <HashtagColor>red</HashtagColor> <passwordset>0</passwordset> <password></password> </Settings> </hashnotes> I then call a function to add a node in the xml, The function is : public static void CreateNoteNodeInXDocument(XDocument argXmlDoc, string argNoteText) { string lastId=(