linq-to-xml

Linq to XML not getting a result

青春壹個敷衍的年華 提交于 2019-12-11 13:29:27
问题 I am creating a List of structs using linq to xml. The linq path does not find the concept elements. I have tried various formulations of this and before I give up and use xpath I am hoping someone can show me the linq way. thanks Here is the xml <response xmlns="http://www.domain.com/api"> <about> <requestId>E9B73CA1F16A670C966BE2BABD3B2B22</requestId> <docId>09E167D994E00B0F511781C40B85AEC3</docId> <systemType>concept</systemType> <configId>odp_2007_l1_1.7k</configId> <contentType>text

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> -

LINQ-to-XML XElement query NULL

假装没事ソ 提交于 2019-12-11 13:19:54
问题 I am trying to UPDATE a child element of something (in this case, "Regex") WHERE one of the child elements ("Name") == selected name ("AccountNumber"). Here is a sample of my XmlDoc <?xml version="1.0" encoding="utf-8"?> <Bill> <Element> <Name>AccountNumber</Name> <Regex></Regex> <Left></Left> <Right></Right> <Top></Top> <Bottom></Bottom> <Relations></Relations> </Element> <Element> <Name>BillDate</Name> <Regex></Regex> <Left></Left> <Right></Right> <Top></Top> <Bottom></Bottom> <Relations><

Reading child nodes from xml string using C#, LINQ

别说谁变了你拦得住时间么 提交于 2019-12-11 13:08:55
问题 - <entry xml:base="http://testserver.windows.net/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/"datetime'2015-08-30T00%3A04%3A02.9193525Z'""> <id>http://testserver.windows.net/Players(PartitionKey='zzz',RowKey='000125')</id> <category term="testServer.Players" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /> <link rel="edit" title=

Parsing unbranched XML in C#

妖精的绣舞 提交于 2019-12-11 11:24:20
问题 I am getting XML from a embedded machine in the below format: <?xml version="1.0" encoding="utf-8"?> <Horizon-Export> <BatchNo.>1</BatchNo.> <SpecimenID>CL1</SpecimenID> <OperatorName>Anuj</OperatorName> <SpecimenAge>1.00</SpecimenAge> <Grade>M12</Grade> <DateofCasting>01/09/2012</DateofCasting> <SpecimenShape>Cube</SpecimenShape> <SpecimenSize>150.00</SpecimenSize> <Area>22,500</Area> <Weight>10.0</Weight> <Density>1.00</Density> <TestDate>17/09/2012</TestDate> <TestTime>9:41:08 AM</TestTime

Linq to XML Get the next node of the same name

妖精的绣舞 提交于 2019-12-11 11:21:06
问题 Here is my XML <assets> <asset> <metadata Id="ItemType" Value="Image"/> <metadata Id="ItemUri" Value="http://blah.png"/> </asset> <asset> <metadata Id="ItemType" Value="Image"/> <metadata Id="ItemUri" Value="http://blah2.png"/> </asset> </assets> How do I get the 2nd <metadata> 's value containing the URI? List<Asset> assets = (from asset in xmlDocument.Descendants("asset") select new Asset { ItemType = asset.Element("metadata").Attribute("Value").Value, ItemUri = asset.Element("metadata")

Matching XML elements to ListBox selected item - C#

久未见 提交于 2019-12-11 11:19:23
问题 I want to make it so the item I have selected in the list box shows its sibling elements in labels. Currently I used my XML file to get the <Name> element and populate my list box with these <Name> values. Now I want to make it so that whenever the <Name> is highlighted in the list box, it will show the <Code> related to that module in a label on the form. i.e. If in the List Box, Algorithms and Data Structures is selected, show its Code,Capacity,Semester and Prerequisites in labels on the

How to load and add elements in an XML tree

三世轮回 提交于 2019-12-11 10:23:18
问题 I have spent the last few days reading here on Stack Overflow, blogs, and MSDN articles. I am clearly lacking some basic understanding of how namespaces, Linq, and XML work and am in need of help. If I had more hair to pull out, it would be in my hand right now :-) Using C# and Linq to XML, I open the following opf.xml file: <?xml version="1.0" encoding="UTF-8"?> <package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier=""> <metadata xmlns:dc="http://purl.org/dc/elements/1

Adding element to XML using linq to XML

十年热恋 提交于 2019-12-11 10:21:50
问题 i have this piece of code which i use to add some elements: string xmlTarget = string.Format(@"<target name='{0}' type='{1}' layout='${{2}}' />", new object[] { target.Name, target.Type, target.Layout }); Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var xmlDoc = XElement.Load(configuration.FilePath); var nlog = xmlDoc.Elements("nlog"); if (nlog.Count() == 0) { return false; } xmlDoc.Elements("nlog").First().Elements("targets").First()

How to get all child elements in the parent element of xml in c#

拜拜、爱过 提交于 2019-12-11 09:54:13
问题 think this is my xml .. <ListOfDestinations> <Destination> <City>Ahmedabad</City> <Title>Cheap Flights to Ahmedabad</Title> <Content> <Top10PlacestoVisit> <subTitle>1</subTitle> <details>d1</details> <subTitle>2</subTitle> <details>d2</details> <subTitle>3</subTitle> <details>d3</details> <subTitle>4</subTitle> <details>d4</details> <subTitle>5</subTitle> <details>d5</details> <subTitle>6</subTitle> <details>d6</details> <subTitle>7</subTitle> <details>d7</details> <subTitle>8</subTitle>