xelement

XElement with colon in the name doesn't work [duplicate]

感情迁移 提交于 2019-12-25 03:17:12
问题 This question already has answers here : XElement namespaces (How to?) (2 answers) Closed 5 years ago . i'm trying to make something like : new XElement("media:thumbnail", new XAttribute("width", "")) but i doesn't work, and i got a error because of the colon ':'. does anyone know how can I solve the problem ? 回答1: That's not how you create an XName with a namespace. You should create an XNamespace with the right URI, and then you can create the right XName easily - personally I use the +

XElement with colon in the name doesn't work [duplicate]

孤人 提交于 2019-12-25 03:17:04
问题 This question already has answers here : XElement namespaces (How to?) (2 answers) Closed 5 years ago . i'm trying to make something like : new XElement("media:thumbnail", new XAttribute("width", "")) but i doesn't work, and i got a error because of the colon ':'. does anyone know how can I solve the problem ? 回答1: That's not how you create an XName with a namespace. You should create an XNamespace with the right URI, and then you can create the right XName easily - personally I use the +

Unable to format Xml for Excel

↘锁芯ラ 提交于 2019-12-25 01:37:32
问题 im trying to format an XML-file so that its possible to open it directly using Microsoft Excel. The problem im having is due to both the default namespace and alias ss: namespace is the same. I can't make excel accept the file otherwise. When try the code, se below, I get an extra xmlns="" attribute on the WorkSheet node. This makes Excel unable to open the file. XNamespace nsDefault = "urn:schemas-microsoft-com:office:spreadsheet"; XElement workbook = new XElement(nsDefault + "Workbook", new

How do I configure WCF client to use XElement and not XmlDocument?

给你一囗甜甜゛ 提交于 2019-12-24 15:13:58
问题 I have an ASMX webservice that returns XElement - (not an .svc WCF service) When consuming the service in Silverlight the client that is generated uses XElement as I want. However in C# .NET 3.5 WCF 'Service Reference' it generates this property using XmlDocument . In C# .NET 4 WCF 'Service Reference' it also generates this property using XmlDocument . So it doesn't seem to be a .NET 4 thing - but a Silverlight thing. How can I configure the WCF client to use XElement also in the standard 3.5

Removing Element from XML in C# [duplicate]

你说的曾经没有我的故事 提交于 2019-12-24 13:09:31
问题 This question already has answers here : How to remove an xml element from file? (3 answers) Closed 5 years ago . below is the xml and i need to remove the Element SMS where code equals to "ZOOMLA". i am using C# code as below but it does not work. and gives me "object reference error" XDocument doc = XDocument.Parse (xml); XElement sms = (from xml2 in doc.Descendants ("SMSList").Descendants ("SMS") where xml2.Attribute ("Code").Value == code select xml2).FirstOrDefault (); sms.Remove (); <

How to check if XElement has any child nodes?

三世轮回 提交于 2019-12-24 07:58:31
问题 I have the following condition, if (myXElement.FirstNode.NodeType == XmlNodeType.CDATA) This throws an exception if there is no FirstNode in myXElement , so I have to check first if there is any. Note that I need to check for nodes not elements. 回答1: var hasDescendants = myElement.Nodes().Any(); 回答2: Sorry for the VB but wouldn't this work If myXElement.Nodes.Count > 0 AndAlso myXElement.FirstNode.NodeType = Xml.XmlNodeType.CDATA Then End If 来源: https://stackoverflow.com/questions/37811047

Adding XML string to XElement

我的未来我决定 提交于 2019-12-24 02:55:51
问题 Hi I need to create an XElement from a string, which can be xml or plain string. This code var doc = new XDocument( new XElement("results", "<result>...</result>") ); produces this <results><result></result></results> But if the string is XML, then I need proper XMl <results><result>...</result></results> Any ideas other than XElement.Parse() because it will throw exception if it is plain text? 回答1: See my answer on Is there an XElement equivalent to XmlWriter.WriteRaw? Essentially, replace a

Including xmlns in my XML file

可紊 提交于 2019-12-23 23:34:47
问题 How can I add the two lines below in my xDocument? I am creating an xml file with Xelements and Xattributes. Can you tell my how can I include this in my xml file please? <Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"> I am getting xmlns="" on the next tag for some reason. A sample is shown below. <Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">

If: XElement Exists, Else Create new one

人盡茶涼 提交于 2019-12-23 18:34:18
问题 My XML File: <?xml version="1.0" encoding="utf-8"?> <SimpleKD> <player name="Tardis"> <kills>0</kills> <deaths>0</deaths> </player> </SimpleKD> First off, I need to check if the username "Tardis" exists in the xml .element("player").attribute("name") . If it doesn't, i need to create it with kills and deaths at zero. If it does, I need to read kills and deaths and set them to variables. I have been using XElement to try and do this.. Thanks! Code used to write the XML: public static string

When saving XML file with XElement, alignment in file changes as well, how to avoid?

穿精又带淫゛_ 提交于 2019-12-23 16:58:35
问题 I am using XElement root = XElement.Load(filepath); to load XML file, then finding things that I need. IEnumerable<XElement> commands = from command in MyCommands where (string) command.Attribute("Number") == Number select command; foreach (XElement command in commands) { command.SetAttributeValue("Group", GroupFound); } When I am done with my changes, I save the file with the following code. root.Save(filepath); When file is saved, all the lines in my XML file are affected. Visual Studio