linq-to-xml

XDocument parses but isnt searchable from string

房东的猫 提交于 2019-12-24 07:29:14
问题 I'm getting a string returned from a website that looks like this <?xml version=\"1.0\" encoding=\"UTF-8\"?><searchResponse requestID=\"500\" status=\"success\"><pso><psoID ID=\"61F2C644-F93A-11DE-8015-73A11AB14291\" targetID=\"mezeoAccount\"><data><email>sholobfc@bluefire.com.au</email><quotaMeg>2048</quotaMeg><quotaUsed>1879736</quotaUsed><active>true</active><unlocked>true</unlocked><allowPublic>true</allowPublic><realm>mezeo</realm><bandwidthQuota>1000000000</bandwidthQuota><billingDay>1<

Get XML Attributes in WPF with a TreeView

倖福魔咒の 提交于 2019-12-24 03:19:51
问题 I am trying to create a treeview in WPF from an XDocument. So far I can create the tree with all nodes and values. Now I would like to add all attributes. Here my problems start ;-) The relevant XAML looks like this: <Window.Resources> <HierarchicalDataTemplate x:Key="NodeTemplate"> <StackPanel Orientation="Horizontal" Focusable="False"> <TextBlock x:Name="tbName" Text="dummy" /> <ItemsControl ItemsSource="{Binding Attributes}"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <TextBlock

c# XML avoid html encode using XDocument

帅比萌擦擦* 提交于 2019-12-24 02:59:34
问题 After creating an xml file using XDocument I end up with: <![CDATA[text]]> and <br /> But I want to keep these as HTML, how do I stop this? 回答1: I assume you are passing a string to an XDocument or XElement constructor somewhere, where that string contains XML. Don't. Instead, use XDocument.Parse(string) or XElement.Parse(string) . See http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.parse.aspx and http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.parse.aspx

Read the values from XML file

懵懂的女人 提交于 2019-12-24 02:47:20
问题 I am using XDocument in order to load XML file, with this content, i am trying to read <pjob:job_variables> nodes content, and for each node in <pjob:job_variables> to get the name and the value, so for <pjob:var name="XMLFilePath">E:\PP\REPC.xt</pjob:var> to get the name XMLFilePath and the value of it E:\PP\REPC.xt <?xml version="1.0"?> <?P_command version="1.0"?> <pjob:job_command xmlns:pjob="http://www.pp.com/schemas" name="SubmitJob"> <pjob:job_variables> <pjob:var name="XMLFilePath">E:

Is there a way to set the default namespace to query from an XDocument?

只愿长相守 提交于 2019-12-24 00:45:35
问题 I don't want to include xmlns + "ElementName" for every element name? XDocument xml = XDocument.Load(@"C:\file.xml"); XNamespace xmlns = "http://www.com/namespace"; var vehicles = from vehicle in xml.Descendants(xmlns + "Element") select vehicle.Element(xmlns + "Item") }; 回答1: Unfortunately this is what you must do when working with LINQ to XML. You must provide the namespace each time you query the document for a particular element. 回答2: Looks like Scott Hanselman has written some notes on

Getting the list

霸气de小男生 提交于 2019-12-24 00:36:44
问题 I am using linq code parsing XML file.This is my code.I want bind detail and image are list. XmlSerializer serializer = new XmlSerializer(typeof(Notchs)); XDocument xmlDoc = XDocument.Parse(dataInXmlFile); Notchs notchs = (Notchs)serializer.Deserialize(xmlDoc.CreateReader()); var query = from l in xmlDoc.Descendants("Person") select new Notch { name = (string)l.Attribute("name").Value, Titles = l.Element("Details").Elements("detail") .Select(s => s.Attribute("games").ToString()) .ToList(),

Parsing xml with inner nodes

删除回忆录丶 提交于 2019-12-24 00:09:57
问题 I'm trying to parse the xml given below: <Item status="SUCCESS" message=""> <ItemDate>12/21/2012 <ItemType>MyType1 <ItemUrl title="ItemTitle">http://www.itemurl1.com</ItemUrl> </ItemType> </ItemDate> <ItemDate>12/22/2012 <ItemType>MyType2 <ItemUrl title="Item2Title">http://www.itemurl2.com</ItemUrl> </ItemType> </ItemDate> </Item> As you could see I'm not sure whether we can call this xml, but this si what I get out of a legacy service. What I'm after is to parse this and load it into an

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

XDocument.Descendants(itemName) - Problems finding qualified name

做~自己de王妃 提交于 2019-12-23 20:00:26
问题 I'm trying to read a XML-RSS-Feed from a website. Therefore I use a async download and create a XDocument with the XDocument.Parse() Method. The Document intends to be very simple, like this: <root> <someAttribute></SomeAttribute> <item>...</item> <item>...</item> </root> Now I want to read out all the items. Therefore I tried: foreach (XElement NewsEntry in xDocument.Descendants("item")) but this doesn't work. So I found a post in this board to use the qualified name, because there are some

Parsing a string in c#

你说的曾经没有我的故事 提交于 2019-12-23 13:16:40
问题 Suppose there is an xml file like below: <Instances> <Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image1.jpg" ImageNumber = "1"/> <Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image2.jpg" ImageNumber = "2"/> <Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg" Location="C:\Series1\Image3.jpg" ImageNumber = "3"/> <Bits = "16" XCoord = "64" YCoord = "64" ZCoord = "64" FileType="jpeg"