linq-to-xml

XElement default namespace on attributes provides unexpected behaviour

丶灬走出姿态 提交于 2019-12-13 15:09:58
问题 I am having trouble creating an XML document that contains a default namespace and a named namespace, hard to explain easier to just show what I am trying to produce... <Root xmlns="http://www.adventure-works.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:SchemaLocation="http://www.SomeLocatation.Com/MySchemaDoc.xsd"> <Book title="Enders Game" author="Orson Scott Card" /> <Book title="I Robot" author="Isaac Asimov" /> </Root> but what I end up with is this... <Root xmlns="http

Update XElement value in XDocument?

时间秒杀一切 提交于 2019-12-13 14:49:08
问题 I have a XDocument with XElements such as this: <PageContent> <Text>My Text</Text> <Image>image.jpg</Image> </PageContent> I want to find the Text element and update its value. I have some LINQ working but its returning the value rather than allowing me to update the XElement and XDocument in return. 回答1: You can't do it in a single LINQ statement - LINQ is about queries, and you're doing an update. You should use LINQ to query for elements you want to update, and then go through the list in

Linq to Xml, keep XDocument loaded?

谁说我不能喝 提交于 2019-12-13 14:41:52
问题 Let's say I'm making a WinForms program that will use an XML document behind the scenes as a persistence mechanism... What are the pros/cons to the two following approaches... Load the XDocument in each method call: public class XmlFoosRepository { string xmlFileName; public XmlFoosRepository(string xmlFileName) { this.xmlFileName = xmlFileName; } public int AddFoo(Foo foo) { var xDoc = XDocument.Load(xmlFileName); // Always call Load() // ... xDoc.Save(xmlFileName); return foo.ID; } public

saving to xml document

北城以北 提交于 2019-12-13 13:22:29
问题 I am " trying " to figure out how to create a Windows Phone 7 application and I would like to update/save an xml file with the following function: XDocument xmlDoc = XDocument.Load("myApp.xml"); xmlDoc.Element("ocd").Add(new XElement("vDetails", new XElement("itemName", this.tb_Name.Text), new XElement("Date", System.DateTime.Now.ToString()), new XElement("itemValue", ""))); xmlDoc.Save("data.xml"); However the xmlDoc.Save line is giving an error: The best overloaded method match for "System

LINQ to XML GroupBy

南楼画角 提交于 2019-12-13 13:12:15
问题 I want to use LINQ to convert input XML to output XML by performing GROUPBY on "Summary" field and SUM up the Balance field. Input XML: <Root> <Account> <Summary>Checking</Summary> <Comprehensive>Interest Checking Account</Comprehensive> <Currency>Dollar</Currency> <Balance>10000000.000000</Balance> </Account> <Account> <Summary>Savings</Summary> <Comprehensive>Market Account</Comprehensive> <Currency>Dollar</Currency> <Balance>20000000.000000</Balance> </Account> <Account> <Summary>Checking<

How to Remove specific attributes in XMLDocument?

半腔热情 提交于 2019-12-13 12:32:52
问题 In my C# codebase, I have a XMLDocument of the form: <A> <B> <C mlns='blabla' yz='blablaaa'> Hi </C> <D mlns='blabla' yz='blablaaa'> How </D> <E mlns='blabla' yz='blablaaa'> Are </E> <F mlns='blabla' yz='blablaaa'> You </F> </B> <B> <C mlns='blabla' yz='blablaaa'> I </C> <D mlns='blabla' yz='blablaaa'> am</D> <E mlns='blabla' yz='blablaaa'> fine</E> <F mlns='blabla' yz='blablaaa'> thanks</F> </B> </A> Using Linq-to-XML or otherwise, I want to remove the mlns and yz attributes for all the

System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first

旧街凉风 提交于 2019-12-13 09:34:24
问题 I got this error while Parse an string to XDocument after edit and save it. But anyone can help me locate error position - The Line 1, position 10475. How can i get that position ??? System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 1, position 10475. if (storage.FileExists("APPSDATA.xml")) { var reader = new StreamReader(new IsolatedStorageFileStream("APPSDATA

Xml Parsing with Dictionary<string, List<MyObject>>

吃可爱长大的小学妹 提交于 2019-12-13 08:59:10
问题 I am working on Windows Phone 8 app development. i have a xml like the below: <array> <dict> <key>SubTopics</key> <array> <dict> <key>ID</key> <array> <string>CD1</string> <string>CD2</string> <string>CD3</string> <string>CD4</string> </array> <key>Title</key> <string>Miscellaneous</string> <key>Desc</key> <string> this is just a text</string> <key>HasItems</key> <true/> </dict> <dict> <key>ID</key> <array> <string>DDC1</string> <string>DDC2</string> <string>DDC3</string> <string>DDC4</string

item in a list of a list is not beeing displayed [closed]

吃可爱长大的小学妹 提交于 2019-12-13 08:25:28
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . it shows me the idfichier, and the nomclient shows system.linq.enumerable... I guess it is showing the type of nomclient. public static void generateCTAF(string pathXml, string outputPDF) { List<FichierCTAF> fc = new List<FichierCTAF>(); fc = getXmlFCtaf(pathXml); foreach (FichierCTAF f in fc) {

Parse xml with varying Key

微笑、不失礼 提交于 2019-12-13 08:22:44
问题 I'm trying to parse the XML below: <plist version="1.0"> <array> <dict> <key>SubTitle</key> <array> <dict> <key>Values</key> <array> <string>D1</string> <string>D2</string> </array> <key>Title</key> <string>Chapter One</string> <key>supportsEdit</key> <true/> </dict> <dict> <key>Values</key> <array> <string>DC1</string> <string>DC2</string> </array> <key>Title</key> <string>Chapter Two</string> <key>supportsEdit</key> <true/> </dict> </array> <key>MainTitle</key> <string>Science</string> <