473,394 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SelectSingleNode problem

hg
Hi!
The input xml file:
<?xml version="1.0" encoding="utf-8" ?>

<!-- Konfiguráció leírása -->

<Konfig xmlns:bk="urn:inifile">

<Konfiguracio>

<szerver neve = "A1"></szerver>

</Konfiguracio>

</Konfig>

XmlDocument xd = new XmlDocument();

xd.Load(Application.StartupPath + "\\Server.xml");

//Create an XmlNamespaceManager for resolving namespaces.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable);

nsmgr.AddNamespace("bk", "urn:inifile");

string xp = "//Konfiguracio/szerver";

XmlNode xn = xd.SelectSingleNode(xp,nsmgr);

Here xn always stays null! Why?

Framework version: 1.0.3705
Nov 12 '05 #1
3 1300
Change
string xp = "//Konfiguracio/szerver";
to

string xp = "//bk:Konfiguracio/bk:szerver";
--
This posting is provided "AS IS" with no warranties, and confers no rights.

"hg" <Hu*********@universalleaf.hu> wrote in message
news:eJ*************@TK2MSFTNGP11.phx.gbl... Hi!
The input xml file:
<?xml version="1.0" encoding="utf-8" ?>

<!-- Konfiguráció leírása -->

<Konfig xmlns:bk="urn:inifile">

<Konfiguracio>

<szerver neve = "A1"></szerver>

</Konfiguracio>

</Konfig>

XmlDocument xd = new XmlDocument();

xd.Load(Application.StartupPath + "\\Server.xml");

//Create an XmlNamespaceManager for resolving namespaces.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable);

nsmgr.AddNamespace("bk", "urn:inifile");

string xp = "//Konfiguracio/szerver";

XmlNode xn = xd.SelectSingleNode(xp,nsmgr);

Here xn always stays null! Why?

Framework version: 1.0.3705

Nov 12 '05 #2
hg
It does not work.

"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> az alábbiakat írta a
következo üzenetben news:3f********@news.microsoft.com...
Change
string xp = "//Konfiguracio/szerver";
to

string xp = "//bk:Konfiguracio/bk:szerver";
--
This posting is provided "AS IS" with no warranties, and confers no

rights.
"hg" <Hu*********@universalleaf.hu> wrote in message
news:eJ*************@TK2MSFTNGP11.phx.gbl...
Hi!
The input xml file:
<?xml version="1.0" encoding="utf-8" ?>

<!-- Konfiguráció leírása -->

<Konfig xmlns:bk="urn:inifile">

<Konfiguracio>

<szerver neve = "A1"></szerver>

</Konfiguracio>

</Konfig>

XmlDocument xd = new XmlDocument();

xd.Load(Application.StartupPath + "\\Server.xml");

//Create an XmlNamespaceManager for resolving namespaces.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable);

nsmgr.AddNamespace("bk", "urn:inifile");

string xp = "//Konfiguracio/szerver";

XmlNode xn = xd.SelectSingleNode(xp,nsmgr);

Here xn always stays null! Why?

Framework version: 1.0.3705


Nov 12 '05 #3
hg wrote:
Here xn always stays null! Why?


Should work. Either your XML is not one you have posted.
The following code works for me:
class Class1
{
[STAThread]
static void Main(string[] args)
{
string xml =
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Konfig xmlns:bk=""urn:inifile"">

<Konfiguracio>

<szerver neve = ""A1""></szerver>

</Konfiguracio>

</Konfig>";
XmlDocument xd = new XmlDocument();

xd.LoadXml(xml);

//Create an XmlNamespaceManager for resolving namespaces.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xd.NameTable);

nsmgr.AddNamespace("bk", "urn:inifile");

string xp = "//Konfiguracio/szerver";

XmlNode xn = xd.SelectSingleNode(xp,nsmgr);

Console.WriteLine(xn.Name);
}
}

Result:
szerver

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John R. | last post by:
I have an application written in C# and i am using MS XML DOM! I have a document with the following structure (only the <DicEntry> - Elements are important): <NewDataSet...
2
by: Edward Yang | last post by:
My XML document has a default namespace specified by xmlns="some_url". Here it is: <?xml version="1.0" encoding="utf-8" ?> <ssmproject name="sample" server="sql"...
7
by: Jason | last post by:
Hi I have an XML file i need to load and read the contents. Here is the top part of the xml file. <Research xsi:schemaLocation="http://www.rixml.org/2002/6/RIXML...
3
by: muscha | last post by:
Hi All, I have this weird problem. I have an xml document and tried to do an XPath query to it. If I use the SelectSingleNode method it throws an exception but it works with SelectNodes method....
4
by: Rune | last post by:
I have two queries that appear to be exactly the same, but one of them returns null while the other one returns a valid result! Can anyone provide an explanation to why this is so? Below is an...
2
by: Claire Reed | last post by:
Dear All, I am repeatedly encountering a problem whilst looping through XML Nodes and I am unsure as to what is going on and how I can get around it. I load the following XML document into an...
2
by: adam | last post by:
I tried so many ways to select the node but its not working, please help. I want to research by the identifier in imsmanifest.xml file, the node could be item or resource. XmlDocument doc = new...
7
by: Sashi | last post by:
Two questions: (1) I can pull the text of an XML element as a string just fine using code as such: strSomeString = myXmlDoc.SelectSingleNode("/Element1/Element2/Element3",...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
0
by: compumate99 | last post by:
I am trying to parse the xml document using selectsinglenode method. I am doing this using Visual Foxpro >>> loResultXml = CreateObject("Microsoft.XMLDOM") With loResultXml .Async = .F. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.