<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx</link><description>There are times when it is useful to know the line number of a node in an XML file. This information can be a helpful to users, particularly if you want to report an error. It can also be convenient to search for a node by line number, but that can, of</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#8967079</link><pubDate>Sat, 27 Sep 2008 00:41:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8967079</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#8967281</link><pubDate>Sat, 27 Sep 2008 05:10:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8967281</guid><dc:creator>ravenex</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the article. I'd like to ask though, can a XDocument be saved back to a file in the exact line numbers as it was loaded? There doesn't seem to be such an option in SaveOptions&lt;/p&gt;
</description></item><item><title>LINQ Farm: Preserving Formats with LINQ to XML</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#8970554</link><pubDate>Tue, 30 Sep 2008 21:08:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8970554</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;In a previous post , you saw how to work with line numbers when using LINQ to XML to read a file. This&lt;/p&gt;
</description></item><item><title>re: LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#8970714</link><pubDate>Wed, 01 Oct 2008 00:00:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8970714</guid><dc:creator>Charlie Calvert</dc:creator><description>&lt;p&gt;Ravenex,&lt;/p&gt;
&lt;p&gt;Thanks for your question. It is interesting. Does the Preserving Formats post linked too above help, or were you after something else?&lt;/p&gt;
&lt;p&gt;- Charlie&lt;/p&gt;
</description></item><item><title>re: LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#8971048</link><pubDate>Wed, 01 Oct 2008 06:02:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8971048</guid><dc:creator>ravenex</dc:creator><description>&lt;p&gt;Charlie,&lt;/p&gt;
&lt;p&gt;The new post does give some insight into how it might be done. My goal was to be able to do least amount of modifications to an XML source file when editing with an editor I wrote. The editor shows the tree hierarchy of XML document, and users can't see the actual text in the source file, so line numbers didn't really matter. It would have just worked, but when the files are checked into repository, reformatting the source files will cause versioning control report more modifications then there need to be. That's why I wanted to do the least amount of modifications when editing, and perserving line numbersis crucial.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;- Ravenex&lt;/p&gt;
</description></item><item><title>re: LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#9001447</link><pubDate>Thu, 16 Oct 2008 07:52:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9001447</guid><dc:creator>SkipSailors</dc:creator><description>&lt;p&gt;I have:&lt;/p&gt;
&lt;p&gt;document.Validate(schemas, (o, e) =&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;Console.WriteLine(&amp;quot;{0} at {1}&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.Message, e.Exception.LineNumber);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;error = true;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;},&lt;/p&gt;
&lt;p&gt;true);&lt;/p&gt;
&lt;p&gt;reporting errors always at line 0. &amp;nbsp;I use the LoadOptions.SetLineInfo. Does this have anything to do with what you are talking about here?&lt;/p&gt;
</description></item><item><title>re: LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#9016038</link><pubDate>Sat, 25 Oct 2008 17:30:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9016038</guid><dc:creator>OpticTygre</dc:creator><description>&lt;p&gt;Hi Charlie,&lt;/p&gt;
&lt;p&gt;I'm actually working with line numbering in VB, attempting to perform more advanced things.&lt;/p&gt;
&lt;p&gt;The IXmlLineInfo interface provides a good option for discovering the line number and line position for the start of an element, node, or text. &amp;nbsp;Is there a way, however to get the ending line number of an element and text?&lt;/p&gt;
&lt;p&gt;Through my endeavors of answering that question, I have discovered some interesting things in Linq to XML. &amp;nbsp;If you're interested, please read my forum comments at &lt;a rel="nofollow" target="_new" href="http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/a485f9b7-58a3-4da3-8654-6c1b53e7f5ba"&gt;http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/a485f9b7-58a3-4da3-8654-6c1b53e7f5ba&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thanks for any advice you can provide!&lt;/p&gt;
</description></item><item><title>re: LINQ Farm: LINQ to XML and Line Numbers</title><link>http://blogs.msdn.com/charlie/archive/2008/09/26/linq-farm-linq-to-xml-and-line-numbers.aspx#9016122</link><pubDate>Sat, 25 Oct 2008 19:46:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9016122</guid><dc:creator>OpticTygre</dc:creator><description>&lt;p&gt;To further explain my comment above, I believe a brief example should be provided. &amp;nbsp;Take the following XML:&lt;/p&gt;
&lt;p&gt;&amp;lt;A&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;B&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;C&amp;gt;Some Text&amp;lt;/C&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;D&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;![CDATA[&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;This is some other data&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;that may take several lines&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;]]&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;lt;/D&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;&amp;lt;/B&amp;gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;/A&amp;gt;&lt;/p&gt;
&lt;p&gt;In this XML, all we know from IXmlLineInfo is the starting line number of each element, and the starting position of each element. &amp;nbsp;We don't know:&lt;/p&gt;
&lt;p&gt;1) The ending line number of each element.&lt;/p&gt;
&lt;p&gt;2) The ending line number of text or CData&lt;/p&gt;
&lt;p&gt;3) The ending line position of each element (though this should be the same as the start position)&lt;/p&gt;
&lt;p&gt;4) The ending line position of text or CData.&lt;/p&gt;
&lt;p&gt;I believe the heart of the problem lies in the fact that even though the NodeType property of an XNode is of type XMLNodeType, the XNode object does not use all of the node types available. &amp;nbsp;Looping through this XNodes of this XML, and printing out the NodeTypes, you will notice that and XNode treats &amp;lt;A&amp;gt; and &amp;lt;/A&amp;gt; both as Elements, and not an Element and EndElement.&lt;/p&gt;
&lt;p&gt;-Jason&lt;/p&gt;
</description></item></channel></rss>