xelement

Difference between XPathEvaluate on XElement or XDocument?

孤街醉人 提交于 2021-02-07 20:42:54
问题 Somewhere in a C# program, I need to get an attribute value from an xml structure. I can reach this xml structure directly as an XElement and have a simple xpath string to get the attribute. However, using XPathEvaluate, I get an empty array most of the time. (Yes, sometimes, the attribute is returned, but mostly it isn't... for the exact same XElement and xpath string...) However, if I first convert the xml to string and reparse it as an XDocument, I do always get the attribute back. Can

Difference between XPathEvaluate on XElement or XDocument?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 20:40:50
问题 Somewhere in a C# program, I need to get an attribute value from an xml structure. I can reach this xml structure directly as an XElement and have a simple xpath string to get the attribute. However, using XPathEvaluate, I get an empty array most of the time. (Yes, sometimes, the attribute is returned, but mostly it isn't... for the exact same XElement and xpath string...) However, if I first convert the xml to string and reparse it as an XDocument, I do always get the attribute back. Can

Linq2SQL storing XElement to SQL Server database removes whitespaces

给你一囗甜甜゛ 提交于 2021-01-29 07:20:19
问题 Can I force System.Data.Linq.DataContext to store XML into a SQL Server table's XML column preserving whitespace or is there any other way? My test code is as follows: Guid MyNewQid = Guid.NewGuid(); using (DataClassesDataContext context = DataClassesDataContext.CreateDataContext()) { Guid myQID = Guid.Parse("{28da4eca-2c1a-4647-xxx-b398d1xxx013}"); FromSwiftBck t2sData = context.GetTable<FromSwiftBck>().FirstOrDefault(o => o.QID == myQID); string messageLoaded = t2sData.CompleteMessage; int

Build XML Dynamically using c#

谁都会走 提交于 2020-01-23 01:07:04
问题 I have to create an XML file dynamically based on the user input. Here is what I came up with and I am struck up with two issues. if there is a collection of same element (MaxOccurs = 10) (For example if the user entered 4 accounts then how should my code be) If there is a choice option. Based on the element chosen the child elements should change. Somebody please help me. Thanks in advance BB My code : XElement req = new XElement("order", new XElement("client", new XAttribute("id", clientId)

NullReferenceException while using XElement

二次信任 提交于 2020-01-17 07:28:12
问题 I have a method that is suppose to edit a xml file: public void EditItem(Item item, string xml) { Data = XDocument.Load(HttpContext.Current.Server.MapPath("~/App_Data/Items/" + xml + ".xml")); XElement node = Data.Root.Elements("item").Where(i => (string)i.Element("ID") == item.ID).FirstOrDefault(); node.SetElementValue("ID", item.ID); node.SetElementValue("Name", item.Name); node.SetElementValue("Type", item.Type); node.SetElementValue("Kr", item.Kr); node.SetElementValue("Euro", item.Euro);

Get XElement by value of its attribute

*爱你&永不变心* 提交于 2020-01-16 05:09:12
问题 I've got the following XML: <rootNode> ... some stuff <ReportCellRef> <dang n="DVCompany" h="0" u="0" o="0" fmt="0"> ... some stuff </dang> </ReportCellRef> </rootNode> And I want get the <dang ...> ... </dang> node as XElement, so I can replace it with another node, provided I have the value of the n attribute. I've got this code: Dim nameToSearch = importNode.Attribute("n").Value Dim replaceable = From dangToTake In xdoc.Elements("ReportCellRef") _ Where CStr(dangToTake.Element("dang")

XElement fails to load file with accented characters

て烟熏妆下的殇ゞ 提交于 2020-01-14 13:22:12
问题 I have a rather curious problem, using the XElement load method to load in a html document (which is well formed checked with HTML Tidy), which work absolutely perfectly for English documents, however moving to French and Spanish docs I'm presented with an XML Exception; XML Exception Invalid character in the given encoding. Line 23, position 43. The method call XElement doc = XElement.Load("example1.html", LoadOptions.None); Sniplet of the html document <font face="Arial" size="3" color="

when WCF method returns XmlElement , the client sees XElement returned?

柔情痞子 提交于 2020-01-13 19:43:06
问题 i return an xmlElement from a WCf method. when i do a service reference in the client, the same method is returning XElement instead of XmlElement. i tried everything: updating the service reference, making a new service reference, but it doesn't help. This is my client: ServiceReference1.BasicServiceClient basicWCfClient = new ServiceReference1.BasicServiceClient(); XmlElement xmlelement = basicWCfClient.GetData(5); basicWCfClient.Close(); i get an error : "Cannot implicitly convert type

LINQ to XML. How to query List<T> with Linq recursively

吃可爱长大的小学妹 提交于 2020-01-06 06:59:22
问题 I'm generating XML file from structs. Some struct members are in List<T> type. I'm using linq queries but I'm stuck at some level. My structs are like this: public struct Project { public string name; public List<Class> classes; } public struct Class { public string name; public int class_id; public List<Var> vars; } public struct Var { public string name; public string description; public int var_id; public List<Element> elements; } public struct Element { public string name; public string

XElement & UTF-8 Issue

百般思念 提交于 2020-01-04 17:49:47
问题 I have a .NET Web Service(.asmx, not .svc) that accepts a string via HTTP POST. The strings it accepts are xml infosets I then parse via XElement.Parse. Once parsed into an XElement instance, I add a node to one of the elements within the instance. The problem I'm having is that if a string representing an xml infoset comes through with then for some reason, me adding a node to the element XElement throws an exception such as "' ', hexadecimal value 0x06, is an invalid character. Line 1,