<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/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>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: const, string and other variables</title><link>https://www.infopathdev.com:443/forums/thread/74905.aspx</link><pubDate>Thu, 02 Feb 2012 21:51:58 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:74905</guid><dc:creator>jaxkookie</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/74905.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=74905</wfw:commentRss><description>&lt;p&gt;You are a rock star! I am not worthy.&lt;/p&gt;
&lt;p&gt;thank you&lt;/p&gt;</description></item><item><title>Re: const, string and other variables</title><link>https://www.infopathdev.com:443/forums/thread/74890.aspx</link><pubDate>Thu, 02 Feb 2012 20:35:46 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:74890</guid><dc:creator>Jimmy</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/74890.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=74890</wfw:commentRss><description>&lt;p&gt;Well, if you&amp;#39;re tired of typing XPathNavigator all the time, you can create an alias for it.&amp;nbsp; Just put this under the other &lt;strong&gt;using&lt;/strong&gt; statements at the top of the file:&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;using &lt;/font&gt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;XPN&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; = System.Xml.XPath.&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;XPathNavigator&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Now you can use &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;XPN root = MainDataSource.CreateNavigator();&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Also, it&amp;#39;s not actually&amp;nbsp;necessary to type MainDataSource here.&amp;nbsp; All you need is CreateNavigator(), so now you&amp;#39;re down to this:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;XPN root = CreateNavigator();&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Also, you can&amp;nbsp;add a function like this:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;XPathNavigator GetNode(XPathNavigator start, string path)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return start.SelectSingleNode(path, NamespaceManager);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;And thanks to that, you can replace that second line you have there with:&lt;/p&gt;
&lt;p&gt;string RegionName = GetNode(root,&amp;nbsp;&amp;nbsp;xpathRegName).Value;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;Is that any better?&lt;/p&gt;&lt;/font&gt;</description></item><item><title>const, string and other variables</title><link>https://www.infopathdev.com:443/forums/thread/74888.aspx</link><pubDate>Thu, 02 Feb 2012 19:50:34 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:74888</guid><dc:creator>jaxkookie</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/74888.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=74888</wfw:commentRss><description>&lt;p&gt;I have been using a bunch of c#, in order to keep the code clean and neat I have started pulling out my xpaths and declaring as const string. One addition item I am using over and over again is converting this&lt;/p&gt;
&lt;p&gt;string RegionName = MainDataSource.CreateNavigator().SelectSingleNode(xpathRegName, NamespaceManager).Value;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;to this&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;XPathNavigator root = MainDataSource.CreateNavigator();&lt;br /&gt;string RegionName = root.SelectSingleNode(xpathRegName, NamespaceManager).Value;&lt;/p&gt;
&lt;p&gt;the problem is I have to write the XPathNavigator in every function. is there a way to write this once and use it many times?&lt;/p&gt;
&lt;p&gt;XPathNavigator root = MainDataSource.CreateNavigator();&lt;/p&gt;</description></item></channel></rss>