473,396 Members | 2,029 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,396 software developers and data experts.

Looking for a better way to handle errors

JJ
Hi all,

Im looking for a better way to handle the exeption if you try to find a
node that doesnt exists?

It usualy breaks in a object exeption.

Now i have to use the try en catch option..

Any other ideas???

thanks in advance

greeting jj
Nov 12 '05 #1
5 1098


JJ wrote:

Im looking for a better way to handle the exeption if you try to find a
node that doesnt exists?


C# pseudo code
XmlNode node = someNode.FirstChild;
if (node != null) {
// use node here
}

You have not told use how exactly you "try to find a node" so the above
is just one example of using the DOM to "try to find a node".

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
JJ
Martin Honnen <ma*******@yahoo.de> wrote in
news:O1**************@TK2MSFTNGP11.phx.gbl:


JJ wrote:

Im looking for a better way to handle the exeption if you try to find
a node that doesnt exists?


C# pseudo code
XmlNode node = someNode.FirstChild;
if (node != null) {
// use node here
}

You have not told use how exactly you "try to find a node" so the
above is just one example of using the DOM to "try to find a node".


Hi,
You are wright..

I use the selectsinglenode("//path/something").innertext
When for some reason somthing doenst exists in the xmldoc it generates
an error.. In my case i would like it to result in nothing..

Thanks for your help
Nov 12 '05 #3


JJ wrote:

I use the selectsinglenode("//path/something").innertext
When for some reason somthing doenst exists in the xmldoc it generates
an error.. In my case i would like it to result in nothing..


Well selectSingleNode returns a node or null (or Nothing in VB) so that
expression above is not good coding, do (VB pseudo code)
node = doc.SelectSingleNode("//path/something")
If Not node Is Nothing Then
' use node or node.InnerText here
End If
instead.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
JJ
Hi martin,

That does the trick..

Thanks..

regards jj
Martin Honnen <ma*******@yahoo.de> wrote in news:eMDuMqPxFHA.2072
@TK2MSFTNGP14.phx.gbl:


JJ wrote:

I use the selectsinglenode("//path/something").innertext
When for some reason somthing doenst exists in the xmldoc it generates
an error.. In my case i would like it to result in nothing..


Well selectSingleNode returns a node or null (or Nothing in VB) so that
expression above is not good coding, do (VB pseudo code)
node = doc.SelectSingleNode("//path/something")
If Not node Is Nothing Then
' use node or node.InnerText here
End If
instead.


Nov 12 '05 #5

JJ wrote:
*Hi all,

Im looking for a better way to handle the exeption if you try to find
a
node that doesnt exists?

It usualy breaks in a object exeption.

Now i have to use the try en catch option..

Any other ideas???

thanks in advance

greeting jj *


I too came across this a lot. The strategy I adopted was to use a
foreach(XmlNode in NodeInQuestion.ChildNodes) and use a switch-case to
go through the possible nodenames-this will allow you to work with only
the nodes that you name, and easily refactored to allow for new ones.
Within the foreach you can set some kind of flag that you can later
check to see if a node existed or not.

Of course, if possible, you should always set up a schema and validate
through that but it may not be what you're looking for.

Hope that helps,
Dan'

--
danprime
------------------------------------------------------------------------
Posted via http://www.mcse.ms
------------------------------------------------------------------------
View this thread: http://www.mcse.ms/message1880477.html

Nov 12 '05 #6

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

Similar topics

15
by: klappnase | last post by:
Hello all, I am trying to internationalize my Tkinter program using gettext and encountered various problems, so it looks like it's not a trivial task. After some "research" I made up a few...
38
by: Jukka K. Korpela | last post by:
As well all know, valid markup is important... but when trying to find a convincing modern argument in favor of this, I found pages like http://www.htmlhelp.com/tools/validator/reasons.html which...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
3
by: figelwump | last post by:
Hello, I'd like to be able to write an application that runs on a Windows XP machine and can capture and handle javascript errors from any web site that a user might encounter while using IE on...
10
by: rcamarda | last post by:
I have created a table that contains buckets to hold activitives of enrollment for each of our admissions officer for each day of an enrollment session. I have an UPDATE that builds rolling totals...
5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
6
by: jobs | last post by:
This code was working, but then stopped working. I don't think I completely understand it. I pass it a formview name and it would loop through checking the value of textboxes. problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.