Click here to Skip to main content
15,911,139 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Console help Pin
tim63731-Oct-07 5:03
tim63731-Oct-07 5:03 
QuestionDatabase user ID/password Pin
#realJSOP30-Oct-07 3:51
professional#realJSOP30-Oct-07 3:51 
AnswerRe: Database user ID/password Pin
Ed.Poore30-Oct-07 4:20
Ed.Poore30-Oct-07 4:20 
AnswerRe: Database user ID/password Pin
Pete O'Hanlon30-Oct-07 4:49
mvePete O'Hanlon30-Oct-07 4:49 
QuestionSelectSingleNode Not Getting Node Pin
#realJSOP29-Oct-07 12:04
professional#realJSOP29-Oct-07 12:04 
AnswerRe: SelectSingleNode Not Getting Node Pin
Ed.Poore29-Oct-07 13:33
Ed.Poore29-Oct-07 13:33 
GeneralRe: SelectSingleNode Not Getting Node Pin
#realJSOP29-Oct-07 23:22
professional#realJSOP29-Oct-07 23:22 
AnswerRe: SelectSingleNode Not Getting Node Pin
Ed.Poore29-Oct-07 13:42
Ed.Poore29-Oct-07 13:42 
Ok, I think I might have got something working for you:
Xml File:
<?xml version="1.0"?>
<configuration xmlns:br="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
	<br:connectionStrings>
		<add name="SQL" connectionString="SQL" />
	</br:connectionStrings>
	<connectionStrings>
		<add name="SQL2" connectionString="SQL2" />
	</connectionStrings>
</configuration>


Code:
using System;
using System.Xml;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			XmlDocument dom = new XmlDocument();
			XmlNamespaceManager manager = new XmlNamespaceManager(dom.NameTable);
			manager.AddNamespace("br", "http://microsoft.com/schemas/VisualStudio/TeamTest/2006");

			dom.Load("Web.config");

			XmlNode groupNode = dom.DocumentElement.SelectSingleNode("br:connectionStrings", manager);

			if (groupNode == null)
				Console.WriteLine("(null)");
			else
				Console.WriteLine(groupNode["add"].Attributes["name"].Value);
		}
	}
}


Basically you need to construct the XmlNamespaceManager like you did but pass it into the SelectSingleNode function so that the function can use that object to resolve the namespaces in the XPath query.

Hope that helps, MS probably have their reasons for implementing it this way but it does seem a bit backwards, surely the NameTable should be populated from the xml file if that's where you read it from.


GeneralRe: SelectSingleNode Not Getting Node Pin
#realJSOP29-Oct-07 23:20
professional#realJSOP29-Oct-07 23:20 
GeneralRe: SelectSingleNode Not Getting Node Pin
Ed.Poore30-Oct-07 0:22
Ed.Poore30-Oct-07 0:22 
GeneralRe: SelectSingleNode Not Getting Node Pin
#realJSOP30-Oct-07 2:42
professional#realJSOP30-Oct-07 2:42 
GeneralRe: SelectSingleNode Not Getting Node Pin
Ed.Poore30-Oct-07 3:06
Ed.Poore30-Oct-07 3:06 
GeneralRe: SelectSingleNode Not Getting Node Pin
#realJSOP30-Oct-07 3:19
professional#realJSOP30-Oct-07 3:19 
GeneralRe: SelectSingleNode Not Getting Node [modified] Pin
#realJSOP30-Oct-07 3:05
professional#realJSOP30-Oct-07 3:05 
GeneralRe: SelectSingleNode Not Getting Node Pin
Ed.Poore30-Oct-07 4:17
Ed.Poore30-Oct-07 4:17 
Question.NET on MAC OS Pin
Fayu29-Oct-07 10:23
Fayu29-Oct-07 10:23 
AnswerRe: .NET on MAC OS Pin
#realJSOP29-Oct-07 12:23
professional#realJSOP29-Oct-07 12:23 
AnswerRe: .NET on MAC OS Pin
Ed.Poore29-Oct-07 13:27
Ed.Poore29-Oct-07 13:27 
AnswerRe: .NET on MAC OS Pin
Pete O'Hanlon30-Oct-07 2:21
mvePete O'Hanlon30-Oct-07 2:21 
QuestionI need help! Threading [modified] Pin
tim63729-Oct-07 9:27
tim63729-Oct-07 9:27 
AnswerRe: I need help! Threading Pin
Luc Pattyn29-Oct-07 9:48
sitebuilderLuc Pattyn29-Oct-07 9:48 
GeneralRe: I need help! Threading Pin
Paul Conrad29-Oct-07 17:33
professionalPaul Conrad29-Oct-07 17:33 
GeneralRe: I need help! Threading Pin
tim63730-Oct-07 2:32
tim63730-Oct-07 2:32 
AnswerRe: I need help! Threading Pin
ganesh197530-Oct-07 3:04
ganesh197530-Oct-07 3:04 
GeneralRe: I need help! Threading Pin
tim63730-Oct-07 4:25
tim63730-Oct-07 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.