linq-to-xml

getting app.config elements in powershell

佐手、 提交于 2019-12-12 17:27:44
问题 config file which looks like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="Environment" value="Dev Environment"/> </appSettings> </configuration> How can i get the value of key "Environment" in Powershell? I mean it should return "Dev Environment" when you select key "Environment". I prefer linq to use here anyone with any idea really appreciate that. 回答1: I recommend xpath. First create an XmlDocument object like this: $xml = [xml] @' <?xml version="1

How to Create Dictionary<int, string> via LINQ to XML?

℡╲_俬逩灬. 提交于 2019-12-12 15:41:37
问题 I have the following XML: <FootNotes> <Line id="10306" reference="*"></Line> <Line id="10308" reference="**"></Line> <Line id="10309" reference="***"></Line> <Line id="10310" reference="****"></Line> <Line id="10311" reference="+"></Line> </FootNotes> and I have the following code where I'm to get a Dictionary<int, string>() object into myObject.FootNotes so that each Line is a Key/Value pair var doc = XElement.Parse(xmlString); var myObject = new { FootNotes = (from fn in doc .Elements(

How to generate XML from JSON with parent node of array items

霸气de小男生 提交于 2019-12-12 15:14:12
问题 I am trying to create an XML document that closely conforms to a C# object graph and its JSON representation, but am having difficulty with the list representation in the XML. Given this graph public class X { public List<A> Aa { get; set; } } public class A { public int B; public bool C; } I took the JSON from the above, and tried converting it a couple of ways: var json = @"{""Aa"":[{""B"":186,""C"":true},{""B"":9,""C"":false},{""B"":182,""C"":true}]}"; var xml = JsonConvert

System.IO.IOException error, can't get access to the file

梦想与她 提交于 2019-12-12 14:28:12
问题 I can't understand where problem is, despite the fact, that this code pretty easy. I have such function: public void WriteToDoc(string path) { XDocument doc = new XDocument(new XElement("General parameters", new XElement("num_path", num_path.Text), new XElement("Gen_Peroid", Gen_Peroid.Text), new XElement("Alg_Perioad", Alg_Perioad.Text)) ); doc.Save(path); // here he gives that exception } num_path.Text , Gen_Peroid.Text and Alg_Perioad.Text are string . This is how I use this function: File

Parsing XML with C#

那年仲夏 提交于 2019-12-12 14:23:04
问题 I have an XML file as follows: I uploaded the XML file : http://dl.dropbox.com/u/10773282/2011/result.xml . It's a machine generated XML, so you might need some XML viewer/editor. I use this C# code to get the elements in CoverageDSPriv/Module/* . using System; using System.Xml; using System.Xml.Linq; namespace HIR { class Dummy { static void Main(String[] argv) { XDocument doc = XDocument.Load("result.xml"); var coveragePriv = doc.Descendants("CoverageDSPriv"); //.First(); var cons =

Editing XML document using C#

*爱你&永不变心* 提交于 2019-12-12 11:35:42
问题 I have been having some trouble working out how to add elements into my XML document, I am wanting to add hotspot information into the xml where the Id is correct (so where id=2 add hotspot information) this is my current XML - <Pages> <Page> <Id>1</Id> <Title>TEST</Title> <ContentUrl>Images\testimg.png</ContentUrl> <Hotspots> <Hotspot> <X>140</X> <Y>202</Y> <Shape>Circle</Shape> <TargetId>2</TargetId> </Hotspot> </Hotspots> <ParentId>0</ParentId> </Page> <Page> <Id>2</Id> <Title>TEST2</Title

Accessing content file in c# web application

不问归期 提交于 2019-12-12 11:32:01
问题 I am having this issue on my mind for 3 days now. I have an xml file that is marked as Content and Always Copy . The file was copied to: C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\bin\XMLMetadata\Actions.1.xml When accessing to the file: //like that: XDocument actions = XDocument.Load("bin\\XMLMetadata\\Actions.1.xml"); //or like that: XDocument actions = XDocument.Load("XMLMetadata\\Actions.1.xml"); //or like that: XDocument actions = XDocument.Load(

How can I use ':' character in a name of XDocument element?

穿精又带淫゛_ 提交于 2019-12-12 10:36:12
问题 I'm using XDocument to create a RSS same below code: var document = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement("rss", new XElement("channel", new XElement("title", "test"), new XElement("dc:creator", "test"), An exception occurring during the execution of this code. The ':' character, hexadecimal value 0x3A, cannot be included in a name. How can I use : character in a name of element? 回答1: To use namespaces, you'll need to create the namespace object first: UPDATED

XDocument prevent invalid characters

只谈情不闲聊 提交于 2019-12-12 09:59:29
问题 I am using XDocument to keep a sort of database. This database consists of registered chatterbots, and I simply have many "bot" nodes with attributes such as "username", "owner", and such. However, occasionally some smart guy decides to make a bot with a very strange character as one of the properties. This makes the XDocument class series throw an exception whenever that node is read, a very large problem because the database fails to save completely as it stops writing to the file as soon

Order xml file using linq2xml

此生再无相见时 提交于 2019-12-12 09:57:43
问题 Following question Filter xml with LINQ2XML After succesfully filtering (removing nodes) from a xml file. I'd like to order by some attribute in nodes. Sample of xml file: <Root> <Group Price="50"> <Item Price="60"/> <Item Price="50"/> <Item Price="70"/> </Group> <Group Price="55"> <Item Price="62"/> <Item Price="57"/> <Item Price="55"/> </Group> <Group Price="61"> <Item Price="62"/> <Item Price="61"/> <Item Price="65"/> </Group> <!--More Group Nodes--> </Root> And I'd like to get: <Root>