linq-to-xml

Windows Phone 7 : Parsing website XML into XDocument

风格不统一 提交于 2020-01-05 05:00:15
问题 I seem to be having an issue on WP7 trying to Parse XML from a website. For some reason it never populates call. No errors, the xml looks good, I am specifying the NS, but still nothing. Am I missing something really simple here? 4 hours in and I am banging my head on the desk. My C# skills are 2 months old, so it could be me (probably will be). This is my code that I am using to Parse the received XML from a website... public void ParseCallSignData(object sender,

XElement & UTF-8 Issue

百般思念 提交于 2020-01-04 17:49:47
问题 I have a .NET Web Service(.asmx, not .svc) that accepts a string via HTTP POST. The strings it accepts are xml infosets I then parse via XElement.Parse. Once parsed into an XElement instance, I add a node to one of the elements within the instance. The problem I'm having is that if a string representing an xml infoset comes through with then for some reason, me adding a node to the element XElement throws an exception such as "' ', hexadecimal value 0x06, is an invalid character. Line 1,

XElement & UTF-8 Issue

£可爱£侵袭症+ 提交于 2020-01-04 17:46:08
问题 I have a .NET Web Service(.asmx, not .svc) that accepts a string via HTTP POST. The strings it accepts are xml infosets I then parse via XElement.Parse. Once parsed into an XElement instance, I add a node to one of the elements within the instance. The problem I'm having is that if a string representing an xml infoset comes through with then for some reason, me adding a node to the element XElement throws an exception such as "' ', hexadecimal value 0x06, is an invalid character. Line 1,

XElement & UTF-8 Issue

萝らか妹 提交于 2020-01-04 17:46:08
问题 I have a .NET Web Service(.asmx, not .svc) that accepts a string via HTTP POST. The strings it accepts are xml infosets I then parse via XElement.Parse. Once parsed into an XElement instance, I add a node to one of the elements within the instance. The problem I'm having is that if a string representing an xml infoset comes through with then for some reason, me adding a node to the element XElement throws an exception such as "' ', hexadecimal value 0x06, is an invalid character. Line 1,

How to get elements value with Linq To XML

↘锁芯ラ 提交于 2020-01-04 09:12:59
问题 Using Linq To XML, how can I get the space_id value (720) from the xml below? I am reading this but I think the namespace in the xml is my stumbling block. <r25:spaces xmlns:r25="http://www.collegenet.com/r25" pubdate="2009-05-05T12:18:18-04:00"> <r25:space id="VE1QOjRhMDAyZThhXzFfMWRkNGY4MA==" crc="" status="new"> <r25:space_id>720</r25:space_id> <r25:space_name>SPACE_720</r25:space_name> <r25:max_capacity>0</r25:max_capacity> </r25:space> </r25:spaces> EDIT Here's where I am: private int

How to get elements value with Linq To XML

白昼怎懂夜的黑 提交于 2020-01-04 09:12:28
问题 Using Linq To XML, how can I get the space_id value (720) from the xml below? I am reading this but I think the namespace in the xml is my stumbling block. <r25:spaces xmlns:r25="http://www.collegenet.com/r25" pubdate="2009-05-05T12:18:18-04:00"> <r25:space id="VE1QOjRhMDAyZThhXzFfMWRkNGY4MA==" crc="" status="new"> <r25:space_id>720</r25:space_id> <r25:space_name>SPACE_720</r25:space_name> <r25:max_capacity>0</r25:max_capacity> </r25:space> </r25:spaces> EDIT Here's where I am: private int

Save attribute value of xml element with single quotes using linq to xml

二次信任 提交于 2020-01-04 03:55:30
问题 How do I make the XDocument object save an attribute value of a element with single quotes? 回答1: If it is absolutely necessary to have single quotes you could write your XML document to a string and then use a string replace to change from single to double quotes. 回答2: I'm not sure that any of the formatting options for LINQ to XML allow you to specify that. Why do you need to? It's a pretty poor kind of XML handler which is going to care about it... 回答3: As long as you use single- and double

Multiple descendants types linq

久未见 提交于 2020-01-04 02:07:08
问题 I sometimes do this: XElement.Descendants("mynodename"); is there a way to do something like this" XElement.Descendants("mynodename or myothernodename"); 回答1: Not in one method call - but you can use: element.Descendants() .Where(x => x.Name.LocalName == "mynodename" || x.Name.LocalName == "myothernodename") 回答2: Or, XElement.Descendants("mynodename") .Union(XElement.Descendants("myothernodename")); Which would sort them by type, then in order of appearance... 来源: https://stackoverflow.com

XDocument Text Node New Line

时间秒杀一切 提交于 2020-01-03 20:04:03
问题 I'm trying to get a newline into a text node using XText from the Linq XML namespace. I have a string which contains newline characters however I need to work out how to convert these to entity characters (i.e. ) rather than just having them appear in the XML as new lines. XElement element = new XElement( "NodeName" ); ... string example = "This is a string\nWith new lines in it\n"; element.Add( new XText( example ) ); The XElement is then written out using an XmlTextWriter which results in

XDocument Text Node New Line

柔情痞子 提交于 2020-01-03 20:01:33
问题 I'm trying to get a newline into a text node using XText from the Linq XML namespace. I have a string which contains newline characters however I need to work out how to convert these to entity characters (i.e. ) rather than just having them appear in the XML as new lines. XElement element = new XElement( "NodeName" ); ... string example = "This is a string\nWith new lines in it\n"; element.Add( new XText( example ) ); The XElement is then written out using an XmlTextWriter which results in