linq-to-xml

Parse XML using XDocument in Windows Phone 8

南笙酒味 提交于 2019-12-11 20:44:00
问题 Can any one tell me how to parse XML which is in this format using XDocument in Windows phone 8 <search total="" totalpages=""> <domain> <makes filter=""> <make cnt="374" image="abc.png">One</make> <make cnt="588" image="bca">Two</make> <make cnt="105" image="tley.png">Three</make> <make cnt="458" image="mw.png">Four</make> </makes> </domain> </search> Right now i am using this code but unable to get the data out. I need image and name from this XML. XDocument xdoc = XDocument.Parse(flickRes)

LINQ TO XML Parse RSS Feed

▼魔方 西西 提交于 2019-12-11 20:25:49
问题 I'm trying to parse an RSS feed using LINQ to Xml This is the rss feed: http://www.surfersvillage.com/rss/rss.xml My code is as follows to try and parse List<RSS> results = null; XNamespace ns = "http://purl.org/rss/1.0/"; XNamespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; XDocument xdoc = XDocument.Load("http://www.surfersvillage.com/rss/rss.xml"); results = (from feed in xdoc.Descendants(rdf + "item") orderby int.Parse(feed.Element("guid").Value) descending let desc = feed

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 =

Scraping XML from a website with VB.NET and LINQ

妖精的绣舞 提交于 2019-12-11 17:10:12
问题 I've been reading thorough the LINQ documentation and looking at some previous answers on Stack Overflow but I'm still pretty confused about how LINQ works. I want to grab some data from a website, but I can't figure out how to get the xml to parse into strings. Here is what I have so far: Public Class Form1 'Dim xml As XDocument Dim ns As XNamespace Dim strXMLSource As String = "http://gd2.mlb.com/components/game/mlb/year_2018/month_03/day_29/gid_2018_03_29_anamlb_oakmlb_1/linescore.xml" Dim

How to get the attribute value of xml using LINQ to XML?

别等时光非礼了梦想. 提交于 2019-12-11 16:53:42
问题 I have the following xml schema. <Rooms> <Room RoomNumber="room1" EMAIL="ssds@dsfd.com" dsfdd=""/> <Room RoomNumber="room2" EMAIL="ssds@sdd.com" dsfdd=""/> </Rooms> I have to return Email address based on the input(input to program is room number). How i can achieve this using LINQ to XML? 回答1: var doc = XDocument.Load(myXmlFilePath); // or doc = XDocument.Parse(myXmlString); string roomNumber = "room1"; var emailQuery = from room in doc.Root.Elements("Room") where (string)room.Attribute(

Linq/XML: grouping results properly within XML element

风流意气都作罢 提交于 2019-12-11 15:45:46
问题 OK, I asked for how to return a Linq query results as XML, and I got the answer here. But there's one little problem: the results do not get grouped logically within the XML. For example: XElement xml = new XElement("States", from s in MyStates from cy in s.Counties from c in cy.Cities where s.Code == "NY" orderby s.Code, cy.Name, c.Name select new XElement("State", new XAttribute("Code", s.Code), new XAttribute("Name", s.Name), new XElement("County", new XAttribute("Name", cy.Name), new

How to get nodes with same name and same attribute name to collection?

帅比萌擦擦* 提交于 2019-12-11 15:29:31
问题 I've got xml files looking like this <?xml version="1.0" encoding="UTF-8"?> <books> <book id="101">3.1256 <auth-name>Idris Polk</auth-name> <auth id="a1">The author is a Professor of Physics at MIT</auth> <ph ll="p1">336451234</ph> <ph ll="p2">336051294</ph> <mail>IP.00@yandex.com</mail> <ph ll="p3">336133291</ph> </book> <book id="105">4.2250 <auth-name>Andre Olo</auth-name> <auth id="a2">The research fellow at NSF</auth> <ph ll="p101">336200316</ph>, <ph ll="p102">336151093</ph>, <ph ll=

Get attribute value of parent node by Linq to XML

随声附和 提交于 2019-12-11 14:27:22
问题 I have a problem parsing a XML file using Linq to XML. My XML structure looks like: <Module> <Variable Name="Variable1" Value="True" /> <Variable Name="Variable2" Value="True" /> <Variable Name="Variable3" Value="True" /> </Task> <Task Name="Task1"> <Variable Name="Task1Variable1" Value ="True" /> <Variable Name=" Task1Variable2" Value ="True" /> </Task> <Task Name="Task2"> <Variable Name="Task2Variable1" Value ="True" /> <Variable Name=" Task2Variable2" Value ="True" /> </Task> </Module>

Finding header value in xml

a 夏天 提交于 2019-12-11 14:22:54
问题 Here my xml is setup as follows: This is coming via a webservice. <doc> <str name="data_id">XXXXXXX</str> <str name="data">YYYY</str> <str name="data2">zzzz</str> ... .. <doc> <doc> <str name="data_id">X1X1X1X1X1X1X1</str> <str name="data">Y1Y1Y1Y1</str> <str name="data2">z1z1z1z1</str> ... .. <doc> I am converting the whole xml into a datatable. How do I get the column header as column attributes. The resulting datatable have to be in the format as data_id data xxxxx yyyy After loading

Deep Copy of XDocument/Element with associated XElement (s)

吃可爱长大的小学妹 提交于 2019-12-11 13:34:10
问题 Ok I have a XDocument BaseDocument = XDocument.Load(@".\Example\Template.xml"); and some DataStructure of XElements (inside the XDocument) that gets generated by a method. This is just an example: Dictionary<string, List<XElement>> ElementMap = GetElementMapping(BaseDocument); I want to make a deep copy of both, Is there a more efficient way than, XDocument copy = new XDocument(BaseDocument); Dictionary<string, List<XElement>> copyElementMap = GetElementMapping(copy); to copy the