PC Review


Reply
Thread Tools Rate Thread

XMLDocument.SelectSingleNode() not working?

 
 
juvi
Guest
Posts: n/a
 
      1st Feb 2009
Hello,

I want change my application to support language files from xml and I
created a language.xml - but my problem is now that I am not able to get a
specific element value back from a node (wanted to use XPath):

xml looks like this:

<language>
<MainDialog>
<panel>
<title>Main Panel</title>
</panel>
</MainDialog>
</language>

I loaded the document with an XmlTextReader to a XmlDocument and wanted to
use the following which has unfortunately no value:

doc.SelectSingleNode("/language/MainDialog/panel").Attributes["title"].Value.ToString();

What am I doing wrong?? Thanks for any help in advance.

BR, juvi
 
Reply With Quote
 
 
 
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      1st Feb 2009
Title is not an attribute, it's a child node.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"juvi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I want change my application to support language files from xml and I
> created a language.xml - but my problem is now that I am not able to get a
> specific element value back from a node (wanted to use XPath):
>
> xml looks like this:
>
> <language>
> <MainDialog>
> <panel>
> <title>Main Panel</title>
> </panel>
> </MainDialog>
> </language>
>
> I loaded the document with an XmlTextReader to a XmlDocument and wanted to
> use the following which has unfortunately no value:
>
> doc.SelectSingleNode("/language/MainDialog/panel").Attributes["title"].Value.ToString();
>
> What am I doing wrong?? Thanks for any help in advance.
>
> BR, juvi



 
Reply With Quote
 
 
 
 
juvi
Guest
Posts: n/a
 
      1st Feb 2009
Thx for reply....ok....if I change the xpath to:

"/language/MainDialog/panel/title"

which method throws me the wanted value back? (I am sorry for this basic
question but I a completly new to System.XML and the documentation did not
help for me)

juvi
 
Reply With Quote
 
juvi
Guest
Posts: n/a
 
      1st Feb 2009
no matter what I try ... I do not get any value back...only an empty string??
looking forward to your reply...

juvi
 
Reply With Quote
 
Christopher Fairbairn [MVP]
Guest
Posts: n/a
 
      2nd Feb 2009
Hi,

"juvi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thx for reply....ok....if I change the xpath to:
> "/language/MainDialog/panel/title"
> which method throws me the wanted value back?


How about XmlNode's InnerText property, for example:

XmlDocument doc = new XmlDocument();
doc.LoadXml(@"
<language>
<MainDialog>
<panel>
<title>Main Panel</title>
</panel>
</MainDialog>
</language>");
XmlNode node = doc.SelectSingleNode("/language/MainDialog/panel/title");
Debug.WriteLine(node.InnerText);

Hope this helps,
Christopher Fairbairn


 
Reply With Quote
 
juvi
Guest
Posts: n/a
 
      2nd Feb 2009
thx for reply.... I tried it now but again: the result is empty when trying
to select through XPath....if going down with nodeindexes then it works ??
strange ... would be happy to get it work with XPath

XNode = doc.SelectSingleNode("/language/MainDialog/panel/title");
s = XNode.InnerText.ToString(); // does not work

s = doc.ChildNodes.Item(0).ChildNodes.Item(0).FirstChild.InnerText; // works

anybody knows what the problem could be?


thx
 
Reply With Quote
 
juvi
Guest
Posts: n/a
 
      8th Feb 2009
Now it works....thank you all....there was a problem with my xmlreader
code...thx juvi

"Christopher Fairbairn [MVP]" wrote:

> Hi,
>
> "juvi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Thx for reply....ok....if I change the xpath to:
> > "/language/MainDialog/panel/title"
> > which method throws me the wanted value back?

>
> How about XmlNode's InnerText property, for example:
>
> XmlDocument doc = new XmlDocument();
> doc.LoadXml(@"
> <language>
> <MainDialog>
> <panel>
> <title>Main Panel</title>
> </panel>
> </MainDialog>
> </language>");
> XmlNode node = doc.SelectSingleNode("/language/MainDialog/panel/title");
> Debug.WriteLine(node.InnerText);
>
> Hope this helps,
> Christopher Fairbairn
>
>
>

 
Reply With Quote
 
Simon Hart [MVP]
Guest
Posts: n/a
 
      15th Feb 2009
If you're using CF 3.5 you could use LINQ to XML - it's alot easier than
XPath.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://www.simonrhart.com

"juvi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Now it works....thank you all....there was a problem with my xmlreader
> code...thx juvi
>
> "Christopher Fairbairn [MVP]" wrote:
>
>> Hi,
>>
>> "juvi" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Thx for reply....ok....if I change the xpath to:
>> > "/language/MainDialog/panel/title"
>> > which method throws me the wanted value back?

>>
>> How about XmlNode's InnerText property, for example:
>>
>> XmlDocument doc = new XmlDocument();
>> doc.LoadXml(@"
>> <language>
>> <MainDialog>
>> <panel>
>> <title>Main Panel</title>
>> </panel>
>> </MainDialog>
>> </language>");
>> XmlNode node = doc.SelectSingleNode("/language/MainDialog/panel/title");
>> Debug.WriteLine(node.InnerText);
>>
>> Hope this helps,
>> Christopher Fairbairn
>>
>>
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Why is Not not Not? =?Utf-8?B?cXVhcnR6?= Microsoft Excel Programming 2 19th May 2005 05:19 AM
Re: Why is Not not Not? Bob Phillips Microsoft Excel Programming 1 18th May 2005 04:24 PM
after installing sp2 links not working, cd writer not found several programs not responding Bonnie Windows XP Help 1 7th Sep 2004 01:37 AM
Computer not booting, not sure if Windows problem or not usenethelp Windows XP Help 1 21st Jul 2004 01:01 PM
Web page requests not loading, Outlook (SMTP) not working - not related to ISP. gerrold Windows XP Internet Explorer 1 26th Sep 2003 05:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 PM.