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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bullrout
    New Member
    • Sep 2007
    • 1

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

    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>(re f this.nodeTosele ct,someNode.Sel ectSingleNode(" anodetoselect") as XmlElement);



    protected T handleNull<T>(r ef T val,XmlElement elmToParse)
    {
    if (elmToParse != null && !string.IsNullO rEmpty(elmToPar se.InnerText))
    {
    val = (T)Convert.Chan geType(elmToPar se, typeof(T));
    return val;
    }
    val = (T)Convert.Chan geType(elmToPar se, typeof(XmlEleme nt));
    return val;
    }
  • Afterlife
    New Member
    • Sep 2007
    • 4

    #2
    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...

    Comment

    Working...