xelement

Appending new XElement adds an entire XML to existing xml in stream

人盡茶涼 提交于 2019-12-12 00:36:08
问题 I have an existing XML stored in the InternalFielStorage as.. <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Root> <Books> <Author name="Sam" /> </Books> </Root> I am trying to append a "title" node under the "Author" node but the when saved, I am seeing a completly new xml added to the existing xml as.. <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Root> <Books> <Author name="Sam" /> </Books> </Root> <?xml version="1.0" encoding="utf-8" standalone="yes"?> <Root> <Books>

How to get a tablerow out of an xelement?

自闭症网瘾萝莉.ら 提交于 2019-12-12 00:29:28
问题 I have this xelement: <adress name="company1" street="street1" City="city1" <branch key="1" value="branch1" /><language key="1" value="langauge1" /> </adress> as you see there are several attributes in the element adress and it inherits the elements branch and language which also containing some attributes. I want a table like this: name street city branchvalue branchkey languagevalue languagekey How can I do this? I can hardcode it, because the xml scheme is everytime the same but, i would

Adding child nodes to an XElement

岁酱吖の 提交于 2019-12-12 00:25:11
问题 I am trying to append objects into an XML file. The problem I currently have is it appends everything at the first level itself. I am trying to have the list as the parent element and list items as the child elements . What I've tried : I came across a few posts where they use loops but I am unable to relate that to my context and code. Code: XDocument xDocument = XDocument.Load(@"C:\Users\hci\Desktop\Nazish\TangramsTool\TangramsTool\patterndata.xml"); XElement root = xDocument.Element(

How to do edit text content keeping it in a CDATA block?

梦想的初衷 提交于 2019-12-11 19:48:06
问题 I want to edit the contents of a cdata block in this an document. Here's a simplified example: <root><![CDATA[pi > 22/7]]></root> I tried var element = XElement.Parse("<root><![CDATA[pi > 22/7]]></root>"); element.Value = element.Value.Replace("> 22/7", "< 22/7"); element.Dump(); However, the result doesn't have a CDATA block. <root>pi < 22/7</root> I wanted <root><![CDATA[pi < 22/7]]></root> How can I achieve that? 回答1: You need to modify value of the XCData element instead : var element =

To convert XElement into int value,

风格不统一 提交于 2019-12-11 18:09:21
问题 I have my loop for childobjects as follows, List<float?> LValues = new List<float?>(); List<float?> IValues = new List<float?>(); List<float?> BValues = new List<float?>(); List<HMData>[] data = new List<HMData>[4]; float? Value_LfromList = 0; float? Value_IfromList = 0; float? Value_BfromList = 0; foreach (var item in Read_xml_for_childobjects_id.Root.Descendants("object")) { data[item] = new List<HMData>(); // Error occuring on this line for (int k = 0; k < 7; k++) { Value_LfromList =

Convert Dictionary<string, string> to xml through exception “Name cannot begin with the '1' character, hexadecimal value 0x31. ” [duplicate]

北城以北 提交于 2019-12-11 17:12:25
问题 This question already has answers here : Name cannot begin with the '1' character, hexadecimal value 0x31. Line 2, position 2 (3 answers) Closed 5 months ago . Here is the code that I tried to convert Dictionary to xml string. XElement xml_code = new XElement("root", myDictionary.Select(item => new XElement(item.Key, item.Value))); Above code throw the error Name cannot begin with the '1' character, hexadecimal value 0x31. snapshot of dictionary 回答1: This might be happening because one or

Find the delta between two xelements using “except” C#

我的未来我决定 提交于 2019-12-11 14:56:17
问题 My first XElement is: XElement sourceFile = new XElement("source", from o in Version1.Element("folder").Elements("folders").ElementAt(0).Elements("folder") where o.Name != null && o.Name == "folder" select new XElement("data", new XElement("name",(string) o.Attribute("name")), new XElement("filesCount", (string)o.Attribute("folderCount")), new XElement("filesCount", (string)o.Attribute("filesCount")) )); //,o) My second is: XElement targetFile = new XElement("target", from o in Version2

XML hidden characters, how to remove Bom

僤鯓⒐⒋嵵緔 提交于 2019-12-11 14:48:13
问题 I am trying to create an XML file through code. The file is being created successfully but my system needed for the file only reads UTF-8. The file is not being loaded successfully as their are some hidden characters. This hidden characters are generated an error. I am thinking that I need to set the bom a false but dont have any idea how. below you can find my code used for generating my file. XElement xElement = new XElement("Transaction", new XElement("TransactionNumber", counter), new

xdocument.root.element and other permutations return null

橙三吉。 提交于 2019-12-11 13:28:56
问题 flow.Name definitely equals the 'name' of one of the flows in the flowData XDocument. XElement rootelem = flowData.Root.Element("flows"); after the above line the rootelem contains the flows element and it's children as expected BUT the below line throws a null reference exception, why? flowData.Root.Element(flow.Name).Remove(); flowData is declared as an XDocument and looks like so: <?xml version="1.0" encoding="UTF-8"?> -<D53ESB> -<comms> <diagnosticemails sender="eventlog"/> </comms> -

Create dynamic xml using xelement in c#

允我心安 提交于 2019-12-11 07:07:14
问题 I want to create xml using XElement as you can see: XDocument RejectedXmlList = new XDocument ( new XDeclaration("1.0", "utf-8", null) ); int RejectCounter = 0; foreach (Parameter Myparameter in Parameters) { if (true) { XElement xelement = new XElement(Myparameter.ParameterName, CurrentData.ToString()); RejectedXmlList.Add(xelement); } } As you can see if the condition is OK the parameter should be added to RejectedXmlList but instead I get this exception: This operation would create an