xelement

XElement.XPathEvaluate not evaluating exponential numbers correctly

只愿长相守 提交于 2019-12-11 04:35:10
问题 In my C# Program, I am loading a System.Xml.Linq.Xelement variable with a portion of an XML file I'm trying to parse and feeding it various XPaths to evaluate values for using the XPathEvaluate() method. My challenge is that my XML has some numbers stored as exponential numbers and the XPath is ignoring them even though I'm reading that XPath 2.0 should allow for these being understood to be numbers. A sample would look as follows: XML ( childNode ): <Parent> <Vals id="Val1"> <abc>1.8</abc> <

XML file data is lost when sudden shutdown is occurred

蹲街弑〆低调 提交于 2019-12-11 02:36:53
问题 I have an application that stores data in XML file every 500 ms using XElement object's .Save("path") method. The problem is : when a sudden shutdown is occurred the content of the file is deleted so on the next run of the application the file can not be used. How to prevent that / make sure the data will not be lost? P.S: I'm using .NET 2010 C# under windows 7 I've made an experiment: instead of writing to the same data.xml file I've created (by copying from the original file) a new file

Is XML Elements Attribute value always data type of string?

依然范特西╮ 提交于 2019-12-11 01:37:23
问题 When I create a XML Document using LINQ, when I add some XElement to Root element with some Attributes and when I read that document`s XElement using LINQ, the returned value of XAttributes.Value is string by default! In order to assign this value to bool type of variable, it is necessary to call function "Convert.ToBoolean()" XDocument Xd = new XDocument(new XElement("Numbers")); Xd.Root.Add(new XElement("13", new XAttribute("Name", "13") , new XAttribute("IsEvenNumber", false) , new

Adding XElement to XML file using Linq to XML

我与影子孤独终老i 提交于 2019-12-10 21:37:10
问题 Using Linq to XML, I am trying to add an XElement to an existing XML file. It has to be done in the Windows Phone .NET framework. Currently my XML file looks like this: <?xml version="1.0" encoding="utf-8"?> <Kids> <Child> <Name>Kid1</Name> <FirstName>hisname</FirstName> </Child> </Kids> and my code looks like this: using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("YourKids.xml", fileMode, store)) { XDocument x = XDocument.Load(stream); XElement t = new XElement("Child"

XElement.Descendants () make it case-insensitive

天大地大妈咪最大 提交于 2019-12-10 18:07:43
问题 XElement.Descendants () method accepts name of element to be find. But it is case-sensitive is there any way to make it case-insensitive 回答1: You can use this: element.Descendants() .Where(x => string.Compare(x.Name, filter, StringComparison.OrdinalIgnoreCase) == 0); 回答2: This way worked for me.. XElement selectedElement = doc.Descendants().Where(x => String.Equals((string)x.Attribute("name"), filtertext, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); 来源: https:/

Fluent NHibernate and XML columns

流过昼夜 提交于 2019-12-10 17:16:26
问题 I'm building a new site from scratch and am considering using Fluent NHibernate for my ORM. I think it'll handle everything easily except, possibly, my XML columns. I've never built a site with NHibernate at all (though I've used Hibernate for Java) so consider me a n00b. Ideally I'd like the XML to be treated as an XElement as Linq-to-SQL does. Can I do this with (fluent) NHibernate? What if I want to use auto mapping? 回答1: You can use the IUserType defined here: https://nhibernate.jira.com

Linq-to-XML XElement.Remove() leaves unwanted whitespace

久未见 提交于 2019-12-10 01:57:02
问题 I have an XDocument that I create from a byte array (received over tcp/ip). I then search for specific xml nodes (XElements) and after retrieving the value 'pop' it off of the Xdocument by calling XElement.Remove(). After all of my parsing is complete, I want to be able to log the xml that I did not parse (the remaining xml in the XDocument). The problem is that there is extra whitespace that remains when XElement.Remove() is called. I want to know the best way to remove this extra whitespace

XElement and List<T>

我的未来我决定 提交于 2019-12-09 16:50:13
问题 I have a class that has the following properties: public class Author { public string FirstName { get; set; } public string LastName { get; set; } } Next, I have a List of Authors like so: List<Author> authors = new List<Author> (); authors.add( new Author { FirstName = "Steven", LastName = "King" }); authors.add( new Author { FirstName = "Homer", LastName = "" }); Now, I am trying to use Linq to XML in order to generate the XML representing my Authors List. new XElement("Authors", new

Creating XML with namespaces and schemas from an XElement

╄→尐↘猪︶ㄣ 提交于 2019-12-08 15:09:35
问题 A longwinded question - please bear with me! I want to programatically create an XML document with namespaces and schemas. Something like <myroot xmlns="http://www.someurl.com/ns/myroot" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someurl.com/ns/myroot http://www.someurl.com/xml/schemas/myschema.xsd"> <sometag>somecontent</sometag> </myroot> I'm using the rather splendid new LINQ stuff (which is new to me), and was hoping to do the above using an

How to convert XElement object into a dataset or datatable?

夙愿已清 提交于 2019-12-08 12:15:36
问题 I'm accessing a SharePoint(2007) list through a service reference of lists.asmx created in my console application. Console application is created in VS2012 and .Net 4.5 framework. ListsSoapClient proxy1 = new ListsSoapClient(); proxy1.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials; proxy1.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; string listName = "List_For_Test";