how to find out a node has text or not ?

  • Thread starter Thread starter C# newbie
  • Start date Start date
C

C# newbie

Hi,

How can I find out a node into an xml file contains text information or not
?


thanks
 
Assuming you already have the XmlNode context

// XmlNode m_objNode = objXml.DocumentElement.SelectSingleNode("XPATH HERE")

if(m_objNode != null

if(m_objNode.InnerText != string.Empty

// Has something here.



Jonathan Ruckert
 
Thanks but

My xml contains :

<first-name>Benjamin</first-name> as you see it's not
<first-name>"Benjamin"</first-name>

so the solution you passed it's not working for it. Any suggestions ?
 
Newbie,

Perhaps you could provide us with more then a small fragment of your
xml file, as well as with the code you use to retrieve and check the value
of the node? The problem probarbly lies in your source code, since the
code which was provided for you performs the correct check.

HTH,

//Andreas
 
Thanks for your response. I have an xml file, since it's huge I'm only
sending part of it.
I've used an xpath query to find some items a user might be looking for
within an xml file, it works just fine. Let's consider this scenario:
User is looking for "#cccc" and the program returns this path:
Test/Params/LinkColor/VisitedLinkColor/TextColor/Footer
but I need to have this :
Test/Params/LinkColor
Test/Params/VisitedLinkColor
Test/Params/TextColor/
Test/Params/Footer

So I'm looking for a way to find out where the path is ended and compare the
text inside the no. Do you have any suggestions on this ?
Thanks in advance for your help

Xml file:

<?xml version="1.0"?>
<Test TestName="empty" TestID="1" StyleUsage="URL"
xmlns="http://www.test.com" TestProgrammer="me" DateTime="2/12/2004 5:00:54
PM">
<Params>
<BackgroundColor>#12509A</BackgroundColor>
<LinkColor>#cccccc</LinkColor>
<VisitedLinkColor>#cccccc</VisitedLinkColor>
<TextColor>#cccccc</TextColor>
<Direction>ltr</Direction>
<BackgroundImage>
</BackgroundImage>
<Header>&lt;table width='600' cellspacing='0' callpadding='0' border='0'
align='center'&gt; &lt;tr&gt;&lt;td&gt;&lt;img
src='http://img.otxresearch.com/images/otxlogo.gif' alt='OTX' width='175'
height='62'&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;br&gt;</Header>
<Footer>&lt;table align=center border='0' Width='600'&gt;
&lt;tr&gt;&lt;td width='50%'&gt;&lt;FONT FACE='Arial,Helvetica' Size='1'
COLOR='#cccccc'&gt;COPYRIGHT &lt;script
language='javascript'&gt;document.write(String.fromCharCode(38));&lt;/script
&gt;copy 2000 - 2004 OTX CORP. All rights reserved.&lt;/font&gt;&lt;/td&gt;
&lt;td width='50%' align='right'&gt;&lt;FONT FACE='Arial,Helvetica' Size='1'
COLOR='#cccccc'&gt;Technical Problems? &lt;a
href='http://www.test.com/support.asp'&gt;Contact Us, please reference Test
content in the subject line&lt;/a&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</Footer>
<CSS>Test.css</CSS>
<MouseOverMessage>
</MouseOverMessage>
</Params>
 
C# newbie said:
My xml contains :

<first-name>Benjamin</first-name> as you see it's not
<first-name>"Benjamin"</first-name>

so the solution you passed it's not working for it. Any suggestions ?

Why do you think that quotes within the text node would make any
difference?
 
Newbie,

I think what Jon was telling is that you do not have to put Benjamin in
double quotes ("") to make it a string in xml, since the who file is already
a textfile. So Benjamin and "Benjamin" are not the same string just as
much Andreas and Benjamin are different strings.

HTH,

//Andreas

C# newbie said:
I didn't know that. so they're same !
 
!!!!!!!!!!!

Andreas Håkansson said:
Newbie,

I think what Jon was telling is that you do not have to put Benjamin in
double quotes ("") to make it a string in xml, since the who file is already
a textfile. So Benjamin and "Benjamin" are not the same string just as
much Andreas and Benjamin are different strings.

HTH,

//Andreas
 
Dear Andreas,

Thanks for your help. Yes I still had problem when I answered !!!!
but now is solved but the thing is that we were getting far from my
question. Of course, I didn't know there is no different between "Bejamin"
and Benjamin and thans for it but nobody answered my question and got me
confused. However yes now it's OK.
Once again thanks
 
Newbie,

Just to set one thing straight so you wont be hunted by this in
the future. "Benjamin" and Benjamin is NOT the same thing.

//Andreas
 
Back
Top