473,473 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

c# object not set to the reference of an object - XmlElement

1 New Member
Hi There,

I have a method which uses some values passed in as xml, at times some of the elements in the document will be null. The document itself has many elements and I wanted to handle the null elements by just using a method wrapped around the element itself rather than using if statements. Could someone helpme out with the syntax so that the method returns back the object please?

thanks in advance, sean


this.someNode = handleNull <XmlElement>(ref this.nodeToselect,someNode.SelectSingleNode("anode toselect") as XmlElement);



protected T handleNull<T>(ref T val,XmlElement elmToParse)
{
if (elmToParse != null && !string.IsNullOrEmpty(elmToParse.InnerText))
{
val = (T)Convert.ChangeType(elmToParse, typeof(T));
return val;
}
val = (T)Convert.ChangeType(elmToParse, typeof(XmlElement));
return val;
}
Sep 8 '07 #1
1 1490
Afterlife
4 New Member
What object should it return if the node or the node content is null?

If you want to be safe return a new empty XmlElement in that case, but if you're using a WSDL, XSD or other schema, check the schema itself. If 'the other side' doesn't comply to your schema you can blame them, but if your schema flaws, it's all up to you to repair it...
Sep 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sean | last post by:
Hi, I am facing a problem, and i don't know why the error is being generated. I am updating a datagrid with an XML file. My code is Protected Sub UpdateCommand(ByVal Sender As Object,...
1
by: Kristian Kjems | last post by:
Look at the Code Snippet below: It is not possible to Deserialize the Animal in animalStr directly because the type of the animal is not known. Deserializing into the abstract type will not work...
2
by: John Bowman | last post by:
Hi, I need to sign a specific node in an XML file that contains analytical data & has a structure something like the following: <DOCUMENT> <RESULT_SET> <TESTVAL> </TESTVAL> ...
5
by: Chris Capon | last post by:
Is there any way to cast a base class object to a derived class datatype when the derived class adds no new fields nor alters the object allocation in any way? The scenario would be where you...
0
by: Kathy Burke | last post by:
I'm providing the following syntax in hopes someone could tell me why I get an object reference error on the second one. The first one works, using an xmlDocument, the second one immediately...
0
by: Igor | last post by:
Hi everyone ! I have a problem with object serialization. I created web service with number of methods. One of them receives object of the next type: public class ObjectClass private szValue...
3
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic...
5
by: David Palau | last post by:
I'm looking for some guidance on what data type would work best as the result output of a web service function method. This web method will return an object that implements a class that is...
3
by: Jeremy | last post by:
I've created a serializable class and put attributes around all the properties that should be serialized. I return the class from a web service, but my problem is that the wsdl for the web service...
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...
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.