How to tell if a string element is null or really null? - DOTNET

This is a discussion on How to tell if a string element is null or really null? - DOTNET ; Here's the issue. You have a class, Class Person { public int id; public string firstname; public string lastname; } when you expose it via webservice, [WebMethod] public void UpdatePerson(Person) { ... } How do I know whether a field ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

How to tell if a string element is null or really null?

  1. Default How to tell if a string element is null or really null?

    Here's the issue.

    You have a class,

    Class Person
    {
    public int id;
    public string firstname;
    public string lastname;
    }

    when you expose it via webservice,

    [WebMethod]
    public void UpdatePerson(Person)
    {
    ...
    }

    How do I know whether a field value has been specified or not? For value
    types, there is that matching XXXXSpecified buddy field, but for string type,
    there doesn't seem to be one.
    So if incoming Xml looks something like this:
    <Person>
    <firstname>Jiho</firstname>
    </Person>

    when deserialized into a Person object, lastname field will contain null,
    which doesn't tell me whether the field is simply missing (thus safely ignored)
    or lastname field should be set to null (in the database, for example).

    Any idea how to go about this?
    Thanks in advance.


    Jiho Han
    Senior Software Engineer
    Infinity Info Systems
    The Sales Technology Experts
    Tel: 212.563.4400 x216
    Fax: 212.760.0540
    jhan@infinityinfo.com
    www.infinityinfo.com



  2. Default Re: How to tell if a string element is null or really null?

    It is as simple as this,

    if( IsNullOrEmpty(person.lastname) )
    // Echo Is null
    else
    // Echo Is not null

    That is only valid for string types. For other kind of reference type, you
    should check if it is equal to null.

    if( person.lastname == null)
    // Echo Is null
    else
    // Echo Is not null

    "Jiho Han" <jihohan@yahoo.com> wrote in message
    news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    > Here's the issue.
    >
    > You have a class,
    >
    > Class Person
    > {
    > public int id;
    > public string firstname;
    > public string lastname;
    > }
    >
    > when you expose it via webservice,
    >
    > [WebMethod]
    > public void UpdatePerson(Person)
    > {
    > ...
    > }
    >
    > How do I know whether a field value has been specified or not? For value
    > types, there is that matching XXXXSpecified buddy field, but for string
    > type, there doesn't seem to be one.
    > So if incoming Xml looks something like this:
    > <Person>
    > <firstname>Jiho</firstname>
    > </Person>
    >
    > when deserialized into a Person object, lastname field will contain null,
    > which doesn't tell me whether the field is simply missing (thus safely
    > ignored) or lastname field should be set to null (in the database, for
    > example).
    >
    > Any idea how to go about this?
    > Thanks in advance.
    >
    >
    > Jiho Han
    > Senior Software Engineer
    > Infinity Info Systems
    > The Sales Technology Experts
    > Tel: 212.563.4400 x216
    > Fax: 212.760.0540
    > jhan@infinityinfo.com
    > www.infinityinfo.com
    >
    >




  3. Default Re: How to tell if a string element is null or really null?

    Pablo,

    Perhaps, it is more of a design question...

    If you want a field to be set to null (think database), how would you specify
    that from the client side?
    If you don't include the field, it's null on the server. If you set it to
    null, it's still null on the server.
    My point is that there seems to be no way of knowing whether the client intended
    a field to be set to null vs. skip the field for processing becasue it's
    missing from the xml.
    i.e.)
    <Person>
    <Lastname>Han</Lastname>
    <Firstname/>
    </Person>

    and

    <Person>
    <Lastname>Han</Lastname>
    </Person>

    deserializes into an identical object state.

    > It is as simple as this,
    >
    > if( IsNullOrEmpty(person.lastname) )
    > // Echo Is null
    > else
    > // Echo Is not null
    > That is only valid for string types. For other kind of reference type,
    > you should check if it is equal to null.
    >
    > if( person.lastname == null)
    > // Echo Is null
    > else
    > // Echo Is not null
    > "Jiho Han" <jihohan@yahoo.com> wrote in message
    > news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >
    >> Here's the issue.
    >>
    >> You have a class,
    >>
    >> Class Person
    >> {
    >> public int id;
    >> public string firstname;
    >> public string lastname;
    >> }
    >> when you expose it via webservice,
    >>
    >> [WebMethod]
    >> public void UpdatePerson(Person)
    >> {
    >> ...
    >> }
    >> How do I know whether a field value has been specified or not? For
    >> value
    >> types, there is that matching XXXXSpecified buddy field, but for
    >> string
    >> type, there doesn't seem to be one.
    >> So if incoming Xml looks something like this:
    >> <Person>
    >> <firstname>Jiho</firstname>
    >> </Person>
    >> when deserialized into a Person object, lastname field will contain
    >> null, which doesn't tell me whether the field is simply missing (thus
    >> safely ignored) or lastname field should be set to null (in the
    >> database, for example).
    >>
    >> Any idea how to go about this?
    >> Thanks in advance.
    >> Jiho Han
    >> Senior Software Engineer
    >> Infinity Info Systems
    >> The Sales Technology Experts
    >> Tel: 212.563.4400 x216
    >> Fax: 212.760.0540
    >> jhan@infinityinfo.com
    >> www.infinityinfo.com




  4. Default Re: How to tell if a string element is null or really null?

    An XML document, and in particular, a SOAP document, is not quite as simple
    as you seem to think. It can indicate whether the value is null or not.
    Example:

    <SomeObject xsi:nil="true" />

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Professional Chicken Salad Alchemist

    Sequence, Selection, Iteration.

    "Jiho Han" <jihohan@yahoo.com> wrote in message
    news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    > Pablo,
    >
    > Perhaps, it is more of a design question...
    >
    > If you want a field to be set to null (think database), how would you
    > specify that from the client side?
    > If you don't include the field, it's null on the server. If you set it to
    > null, it's still null on the server.
    > My point is that there seems to be no way of knowing whether the client
    > intended a field to be set to null vs. skip the field for processing
    > becasue it's missing from the xml.
    > i.e.)
    > <Person>
    > <Lastname>Han</Lastname>
    > <Firstname/>
    > </Person>
    >
    > and
    > <Person>
    > <Lastname>Han</Lastname>
    > </Person>
    >
    > deserializes into an identical object state.
    >
    >> It is as simple as this,
    >>
    >> if( IsNullOrEmpty(person.lastname) )
    >> // Echo Is null
    >> else
    >> // Echo Is not null
    >> That is only valid for string types. For other kind of reference type,
    >> you should check if it is equal to null.
    >>
    >> if( person.lastname == null)
    >> // Echo Is null
    >> else
    >> // Echo Is not null
    >> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>
    >>> Here's the issue.
    >>>
    >>> You have a class,
    >>>
    >>> Class Person
    >>> {
    >>> public int id;
    >>> public string firstname;
    >>> public string lastname;
    >>> }
    >>> when you expose it via webservice,
    >>>
    >>> [WebMethod]
    >>> public void UpdatePerson(Person)
    >>> {
    >>> ...
    >>> }
    >>> How do I know whether a field value has been specified or not? For
    >>> value
    >>> types, there is that matching XXXXSpecified buddy field, but for
    >>> string
    >>> type, there doesn't seem to be one.
    >>> So if incoming Xml looks something like this:
    >>> <Person>
    >>> <firstname>Jiho</firstname>
    >>> </Person>
    >>> when deserialized into a Person object, lastname field will contain
    >>> null, which doesn't tell me whether the field is simply missing (thus
    >>> safely ignored) or lastname field should be set to null (in the
    >>> database, for example).
    >>>
    >>> Any idea how to go about this?
    >>> Thanks in advance.
    >>> Jiho Han
    >>> Senior Software Engineer
    >>> Infinity Info Systems
    >>> The Sales Technology Experts
    >>> Tel: 212.563.4400 x216
    >>> Fax: 212.760.0540
    >>> jhan@infinityinfo.com
    >>> www.infinityinfo.com

    >
    >




  5. Default Re: How to tell if a string element is null or really null?

    Kevin,

    I understand that the xml received by the soap endpoint is different. However,
    when the xml document is deserialized into an object, there is no difference
    - or rather I don't know of a way - between:

    <Person>
    <Lastname xsi:nil = "true"/>
    </Person>

    vs.

    <Person>
    </Person>

    When it gets deserialized into an object,

    Person person = <from soap response>
    person.Lastname == null // true for both!

    If there is a way to tell the difference, that'd be great. Is there some
    kind of a hook into the soap deserialization scheme?

    > An XML document, and in particular, a SOAP document, is not quite as
    > simple as you seem to think. It can indicate whether the value is null
    > or not. Example:
    >
    > <SomeObject xsi:nil="true" />
    >
    > Kevin Spencer
    > Microsoft MVP
    > Professional Chicken Salad Alchemist
    > Sequence, Selection, Iteration.
    >
    > "Jiho Han" <jihohan@yahoo.com> wrote in message
    > news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    >
    >> Pablo,
    >>
    >> Perhaps, it is more of a design question...
    >>
    >> If you want a field to be set to null (think database), how would you
    >> specify that from the client side?
    >> If you don't include the field, it's null on the server. If you set
    >> it to
    >> null, it's still null on the server.
    >> My point is that there seems to be no way of knowing whether the
    >> client
    >> intended a field to be set to null vs. skip the field for processing
    >> becasue it's missing from the xml.
    >> i.e.)
    >> <Person>
    >> <Lastname>Han</Lastname>
    >> <Firstname/>
    >> </Person>
    >> and
    >> <Person>
    >> <Lastname>Han</Lastname>
    >> </Person>
    >> deserializes into an identical object state.
    >>
    >>> It is as simple as this,
    >>>
    >>> if( IsNullOrEmpty(person.lastname) )
    >>> // Echo Is null
    >>> else
    >>> // Echo Is not null
    >>> That is only valid for string types. For other kind of reference
    >>> type,
    >>> you should check if it is equal to null.
    >>> if( person.lastname == null)
    >>> // Echo Is null
    >>> else
    >>> // Echo Is not null
    >>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>>> Here's the issue.
    >>>>
    >>>> You have a class,
    >>>>
    >>>> Class Person
    >>>> {
    >>>> public int id;
    >>>> public string firstname;
    >>>> public string lastname;
    >>>> }
    >>>> when you expose it via webservice,
    >>>> [WebMethod]
    >>>> public void UpdatePerson(Person)
    >>>> {
    >>>> ...
    >>>> }
    >>>> How do I know whether a field value has been specified or not? For
    >>>> value
    >>>> types, there is that matching XXXXSpecified buddy field, but for
    >>>> string
    >>>> type, there doesn't seem to be one.
    >>>> So if incoming Xml looks something like this:
    >>>> <Person>
    >>>> <firstname>Jiho</firstname>
    >>>> </Person>
    >>>> when deserialized into a Person object, lastname field will contain
    >>>> null, which doesn't tell me whether the field is simply missing
    >>>> (thus
    >>>> safely ignored) or lastname field should be set to null (in the
    >>>> database, for example).
    >>>> Any idea how to go about this?
    >>>> Thanks in advance.
    >>>> Jiho Han
    >>>> Senior Software Engineer
    >>>> Infinity Info Systems
    >>>> The Sales Technology Experts
    >>>> Tel: 212.563.4400 x216
    >>>> Fax: 212.760.0540
    >>>> jhan@infinityinfo.com
    >>>> www.infinityinfo.com




  6. Default Re: How to tell if a string element is null or really null?

    I haven't personally encountered this situation. However, I think that
    applying some custom formatting to the SOAP XSD might do the trick. See
    http://msdn2.microsoft.com/en-us/library/k1y9z356.aspx

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Professional Chicken Salad Alchemist

    Sequence, Selection, Iteration.


    "Jiho Han" <jihohan@yahoo.com> wrote in message
    news:a19ab9b61ba658c87ddbf521dbd8@msnews.microsoft.com...
    > Kevin,
    >
    > I understand that the xml received by the soap endpoint is different.
    > However, when the xml document is deserialized into an object, there is no
    > difference - or rather I don't know of a way - between:
    >
    > <Person>
    > <Lastname xsi:nil = "true"/>
    > </Person>
    >
    > vs.
    >
    > <Person>
    > </Person>
    >
    > When it gets deserialized into an object,
    >
    > Person person = <from soap response>
    > person.Lastname == null // true for both!
    >
    > If there is a way to tell the difference, that'd be great. Is there some
    > kind of a hook into the soap deserialization scheme?
    >> An XML document, and in particular, a SOAP document, is not quite as
    >> simple as you seem to think. It can indicate whether the value is null
    >> or not. Example:
    >>
    >> <SomeObject xsi:nil="true" />
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Professional Chicken Salad Alchemist
    >> Sequence, Selection, Iteration.
    >>
    >> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >> news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    >>
    >>> Pablo,
    >>>
    >>> Perhaps, it is more of a design question...
    >>>
    >>> If you want a field to be set to null (think database), how would you
    >>> specify that from the client side?
    >>> If you don't include the field, it's null on the server. If you set
    >>> it to
    >>> null, it's still null on the server.
    >>> My point is that there seems to be no way of knowing whether the
    >>> client
    >>> intended a field to be set to null vs. skip the field for processing
    >>> becasue it's missing from the xml.
    >>> i.e.)
    >>> <Person>
    >>> <Lastname>Han</Lastname>
    >>> <Firstname/>
    >>> </Person>
    >>> and
    >>> <Person>
    >>> <Lastname>Han</Lastname>
    >>> </Person>
    >>> deserializes into an identical object state.
    >>>
    >>>> It is as simple as this,
    >>>>
    >>>> if( IsNullOrEmpty(person.lastname) )
    >>>> // Echo Is null
    >>>> else
    >>>> // Echo Is not null
    >>>> That is only valid for string types. For other kind of reference
    >>>> type,
    >>>> you should check if it is equal to null.
    >>>> if( person.lastname == null)
    >>>> // Echo Is null
    >>>> else
    >>>> // Echo Is not null
    >>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>>>> Here's the issue.
    >>>>>
    >>>>> You have a class,
    >>>>>
    >>>>> Class Person
    >>>>> {
    >>>>> public int id;
    >>>>> public string firstname;
    >>>>> public string lastname;
    >>>>> }
    >>>>> when you expose it via webservice,
    >>>>> [WebMethod]
    >>>>> public void UpdatePerson(Person)
    >>>>> {
    >>>>> ...
    >>>>> }
    >>>>> How do I know whether a field value has been specified or not? For
    >>>>> value
    >>>>> types, there is that matching XXXXSpecified buddy field, but for
    >>>>> string
    >>>>> type, there doesn't seem to be one.
    >>>>> So if incoming Xml looks something like this:
    >>>>> <Person>
    >>>>> <firstname>Jiho</firstname>
    >>>>> </Person>
    >>>>> when deserialized into a Person object, lastname field will contain
    >>>>> null, which doesn't tell me whether the field is simply missing
    >>>>> (thus
    >>>>> safely ignored) or lastname field should be set to null (in the
    >>>>> database, for example).
    >>>>> Any idea how to go about this?
    >>>>> Thanks in advance.
    >>>>> Jiho Han
    >>>>> Senior Software Engineer
    >>>>> Infinity Info Systems
    >>>>> The Sales Technology Experts
    >>>>> Tel: 212.563.4400 x216
    >>>>> Fax: 212.760.0540
    >>>>> jhan@infinityinfo.com
    >>>>> www.infinityinfo.com

    >
    >




  7. Default Re: How to tell if a string element is null or really null?

    Hello Kevin,

    I am not exactly sure that will help. It doesn't seem to matter how the
    SOAP is formatted, the end result is that when the XmlSerializer consumes
    an incoming xml, it's same. Once in object form, there is no way to tell
    which format it came in.
    This is a bit frustrating. Thanks for your help though.

    Jiho

    > I haven't personally encountered this situation. However, I think that
    > applying some custom formatting to the SOAP XSD might do the trick.
    > See http://msdn2.microsoft.com/en-us/library/k1y9z356.aspx
    >
    > Kevin Spencer
    > Microsoft MVP
    > Professional Chicken Salad Alchemist
    > Sequence, Selection, Iteration.
    >
    > "Jiho Han" <jihohan@yahoo.com> wrote in message
    > news:a19ab9b61ba658c87ddbf521dbd8@msnews.microsoft.com...
    >
    >> Kevin,
    >>
    >> I understand that the xml received by the soap endpoint is different.
    >> However, when the xml document is deserialized into an object, there
    >> is no difference - or rather I don't know of a way - between:
    >>
    >> <Person>
    >> <Lastname xsi:nil = "true"/>
    >> </Person>
    >> vs.
    >>
    >> <Person>
    >> </Person>
    >> When it gets deserialized into an object,
    >>
    >> Person person = <from soap response>
    >> person.Lastname == null // true for both!
    >> If there is a way to tell the difference, that'd be great. Is there
    >> some kind of a hook into the soap deserialization scheme?
    >>
    >>> An XML document, and in particular, a SOAP document, is not quite as
    >>> simple as you seem to think. It can indicate whether the value is
    >>> null or not. Example:
    >>>
    >>> <SomeObject xsi:nil="true" />
    >>>
    >>> Kevin Spencer
    >>> Microsoft MVP
    >>> Professional Chicken Salad Alchemist
    >>> Sequence, Selection, Iteration.
    >>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>> news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    >>>> Pablo,
    >>>>
    >>>> Perhaps, it is more of a design question...
    >>>>
    >>>> If you want a field to be set to null (think database), how would
    >>>> you
    >>>> specify that from the client side?
    >>>> If you don't include the field, it's null on the server. If you
    >>>> set
    >>>> it to
    >>>> null, it's still null on the server.
    >>>> My point is that there seems to be no way of knowing whether the
    >>>> client
    >>>> intended a field to be set to null vs. skip the field for
    >>>> processing
    >>>> becasue it's missing from the xml.
    >>>> i.e.)
    >>>> <Person>
    >>>> <Lastname>Han</Lastname>
    >>>> <Firstname/>
    >>>> </Person>
    >>>> and
    >>>> <Person>
    >>>> <Lastname>Han</Lastname>
    >>>> </Person>
    >>>> deserializes into an identical object state.
    >>>>> It is as simple as this,
    >>>>>
    >>>>> if( IsNullOrEmpty(person.lastname) )
    >>>>> // Echo Is null
    >>>>> else
    >>>>> // Echo Is not null
    >>>>> That is only valid for string types. For other kind of reference
    >>>>> type,
    >>>>> you should check if it is equal to null.
    >>>>> if( person.lastname == null)
    >>>>> // Echo Is null
    >>>>> else
    >>>>> // Echo Is not null
    >>>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>>> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>>>>> Here's the issue.
    >>>>>>
    >>>>>> You have a class,
    >>>>>>
    >>>>>> Class Person
    >>>>>> {
    >>>>>> public int id;
    >>>>>> public string firstname;
    >>>>>> public string lastname;
    >>>>>> }
    >>>>>> when you expose it via webservice,
    >>>>>> [WebMethod]
    >>>>>> public void UpdatePerson(Person)
    >>>>>> {
    >>>>>> ...
    >>>>>> }
    >>>>>> How do I know whether a field value has been specified or not?
    >>>>>> For
    >>>>>> value
    >>>>>> types, there is that matching XXXXSpecified buddy field, but for
    >>>>>> string
    >>>>>> type, there doesn't seem to be one.
    >>>>>> So if incoming Xml looks something like this:
    >>>>>> <Person>
    >>>>>> <firstname>Jiho</firstname>
    >>>>>> </Person>
    >>>>>> when deserialized into a Person object, lastname field will
    >>>>>> contain
    >>>>>> null, which doesn't tell me whether the field is simply missing
    >>>>>> (thus
    >>>>>> safely ignored) or lastname field should be set to null (in the
    >>>>>> database, for example).
    >>>>>> Any idea how to go about this?
    >>>>>> Thanks in advance.
    >>>>>> Jiho Han
    >>>>>> Senior Software Engineer
    >>>>>> Infinity Info Systems
    >>>>>> The Sales Technology Experts
    >>>>>> Tel: 212.563.4400 x216
    >>>>>> Fax: 212.760.0540
    >>>>>> jhan@infinityinfo.com
    >>>>>> www.infinityinfo.com




  8. Default Re: How to tell if a string element is null or really null?

    Is there a difference between the two in the XML InfoSet model?

    John

    "Jiho Han" <jihohan@yahoo.com> wrote in message
    news:a19ab9b61bad38c87e27a332ada9@msnews.microsoft.com...
    > Hello Kevin,
    >
    > I am not exactly sure that will help. It doesn't seem to matter how the
    > SOAP is formatted, the end result is that when the XmlSerializer consumes
    > an incoming xml, it's same. Once in object form, there is no way to tell
    > which format it came in.
    > This is a bit frustrating. Thanks for your help though.
    >
    > Jiho
    >
    >> I haven't personally encountered this situation. However, I think that
    >> applying some custom formatting to the SOAP XSD might do the trick.
    >> See http://msdn2.microsoft.com/en-us/library/k1y9z356.aspx
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Professional Chicken Salad Alchemist
    >> Sequence, Selection, Iteration.
    >>
    >> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >> news:a19ab9b61ba658c87ddbf521dbd8@msnews.microsoft.com...
    >>
    >>> Kevin,
    >>>
    >>> I understand that the xml received by the soap endpoint is different.
    >>> However, when the xml document is deserialized into an object, there
    >>> is no difference - or rather I don't know of a way - between:
    >>>
    >>> <Person>
    >>> <Lastname xsi:nil = "true"/>
    >>> </Person>
    >>> vs.
    >>>
    >>> <Person>
    >>> </Person>
    >>> When it gets deserialized into an object,
    >>>
    >>> Person person = <from soap response>
    >>> person.Lastname == null // true for both!
    >>> If there is a way to tell the difference, that'd be great. Is there
    >>> some kind of a hook into the soap deserialization scheme?
    >>>
    >>>> An XML document, and in particular, a SOAP document, is not quite as
    >>>> simple as you seem to think. It can indicate whether the value is
    >>>> null or not. Example:
    >>>>
    >>>> <SomeObject xsi:nil="true" />
    >>>>
    >>>> Kevin Spencer
    >>>> Microsoft MVP
    >>>> Professional Chicken Salad Alchemist
    >>>> Sequence, Selection, Iteration.
    >>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>> news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    >>>>> Pablo,
    >>>>>
    >>>>> Perhaps, it is more of a design question...
    >>>>>
    >>>>> If you want a field to be set to null (think database), how would
    >>>>> you
    >>>>> specify that from the client side?
    >>>>> If you don't include the field, it's null on the server. If you
    >>>>> set
    >>>>> it to
    >>>>> null, it's still null on the server.
    >>>>> My point is that there seems to be no way of knowing whether the
    >>>>> client
    >>>>> intended a field to be set to null vs. skip the field for
    >>>>> processing
    >>>>> becasue it's missing from the xml.
    >>>>> i.e.)
    >>>>> <Person>
    >>>>> <Lastname>Han</Lastname>
    >>>>> <Firstname/>
    >>>>> </Person>
    >>>>> and
    >>>>> <Person>
    >>>>> <Lastname>Han</Lastname>
    >>>>> </Person>
    >>>>> deserializes into an identical object state.
    >>>>>> It is as simple as this,
    >>>>>>
    >>>>>> if( IsNullOrEmpty(person.lastname) )
    >>>>>> // Echo Is null
    >>>>>> else
    >>>>>> // Echo Is not null
    >>>>>> That is only valid for string types. For other kind of reference
    >>>>>> type,
    >>>>>> you should check if it is equal to null.
    >>>>>> if( person.lastname == null)
    >>>>>> // Echo Is null
    >>>>>> else
    >>>>>> // Echo Is not null
    >>>>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>>>> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>>>>>> Here's the issue.
    >>>>>>>
    >>>>>>> You have a class,
    >>>>>>>
    >>>>>>> Class Person
    >>>>>>> {
    >>>>>>> public int id;
    >>>>>>> public string firstname;
    >>>>>>> public string lastname;
    >>>>>>> }
    >>>>>>> when you expose it via webservice,
    >>>>>>> [WebMethod]
    >>>>>>> public void UpdatePerson(Person)
    >>>>>>> {
    >>>>>>> ...
    >>>>>>> }
    >>>>>>> How do I know whether a field value has been specified or not?
    >>>>>>> For
    >>>>>>> value
    >>>>>>> types, there is that matching XXXXSpecified buddy field, but for
    >>>>>>> string
    >>>>>>> type, there doesn't seem to be one.
    >>>>>>> So if incoming Xml looks something like this:
    >>>>>>> <Person>
    >>>>>>> <firstname>Jiho</firstname>
    >>>>>>> </Person>
    >>>>>>> when deserialized into a Person object, lastname field will
    >>>>>>> contain
    >>>>>>> null, which doesn't tell me whether the field is simply missing
    >>>>>>> (thus
    >>>>>>> safely ignored) or lastname field should be set to null (in the
    >>>>>>> database, for example).
    >>>>>>> Any idea how to go about this?
    >>>>>>> Thanks in advance.
    >>>>>>> Jiho Han
    >>>>>>> Senior Software Engineer
    >>>>>>> Infinity Info Systems
    >>>>>>> The Sales Technology Experts
    >>>>>>> Tel: 212.563.4400 x216
    >>>>>>> Fax: 212.760.0540
    >>>>>>> jhan@infinityinfo.com
    >>>>>>> www.infinityinfo.com

    >
    >




  9. Default Re: How to tell if a string element is null or really null?

    John,

    I don't know, you tell me, are these two different?

    <Person>
    <FirstName xsi:nil = "true" />
    <Person>

    <Person>
    </Person>

    Thanks

    > Is there a difference between the two in the XML InfoSet model?
    >
    > John
    >
    > "Jiho Han" <jihohan@yahoo.com> wrote in message
    > news:a19ab9b61bad38c87e27a332ada9@msnews.microsoft.com...
    >
    >> Hello Kevin,
    >>
    >> I am not exactly sure that will help. It doesn't seem to matter how
    >> the
    >> SOAP is formatted, the end result is that when the XmlSerializer
    >> consumes
    >> an incoming xml, it's same. Once in object form, there is no way to
    >> tell
    >> which format it came in.
    >> This is a bit frustrating. Thanks for your help though.
    >> Jiho
    >>
    >>> I haven't personally encountered this situation. However, I think
    >>> that applying some custom formatting to the SOAP XSD might do the
    >>> trick. See http://msdn2.microsoft.com/en-us/library/k1y9z356.aspx
    >>>
    >>> Kevin Spencer
    >>> Microsoft MVP
    >>> Professional Chicken Salad Alchemist
    >>> Sequence, Selection, Iteration.
    >>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>> news:a19ab9b61ba658c87ddbf521dbd8@msnews.microsoft.com...
    >>>> Kevin,
    >>>>
    >>>> I understand that the xml received by the soap endpoint is
    >>>> different. However, when the xml document is deserialized into an
    >>>> object, there is no difference - or rather I don't know of a way -
    >>>> between:
    >>>>
    >>>> <Person>
    >>>> <Lastname xsi:nil = "true"/>
    >>>> </Person>
    >>>> vs.
    >>>> <Person>
    >>>> </Person>
    >>>> When it gets deserialized into an object,
    >>>> Person person = <from soap response>
    >>>> person.Lastname == null // true for both!
    >>>> If there is a way to tell the difference, that'd be great. Is
    >>>> there
    >>>> some kind of a hook into the soap deserialization scheme?
    >>>>> An XML document, and in particular, a SOAP document, is not quite
    >>>>> as simple as you seem to think. It can indicate whether the value
    >>>>> is null or not. Example:
    >>>>>
    >>>>> <SomeObject xsi:nil="true" />
    >>>>>
    >>>>> Kevin Spencer
    >>>>> Microsoft MVP
    >>>>> Professional Chicken Salad Alchemist
    >>>>> Sequence, Selection, Iteration.
    >>>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>>> news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    >>>>>> Pablo,
    >>>>>>
    >>>>>> Perhaps, it is more of a design question...
    >>>>>>
    >>>>>> If you want a field to be set to null (think database), how would
    >>>>>> you
    >>>>>> specify that from the client side?
    >>>>>> If you don't include the field, it's null on the server. If you
    >>>>>> set
    >>>>>> it to
    >>>>>> null, it's still null on the server.
    >>>>>> My point is that there seems to be no way of knowing whether the
    >>>>>> client
    >>>>>> intended a field to be set to null vs. skip the field for
    >>>>>> processing
    >>>>>> becasue it's missing from the xml.
    >>>>>> i.e.)
    >>>>>> <Person>
    >>>>>> <Lastname>Han</Lastname>
    >>>>>> <Firstname/>
    >>>>>> </Person>
    >>>>>> and
    >>>>>> <Person>
    >>>>>> <Lastname>Han</Lastname>
    >>>>>> </Person>
    >>>>>> deserializes into an identical object state.
    >>>>>>> It is as simple as this,
    >>>>>>>
    >>>>>>> if( IsNullOrEmpty(person.lastname) )
    >>>>>>> // Echo Is null
    >>>>>>> else
    >>>>>>> // Echo Is not null
    >>>>>>> That is only valid for string types. For other kind of reference
    >>>>>>> type,
    >>>>>>> you should check if it is equal to null.
    >>>>>>> if( person.lastname == null)
    >>>>>>> // Echo Is null
    >>>>>>> else
    >>>>>>> // Echo Is not null
    >>>>>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>>>>> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>>>>>>> Here's the issue.
    >>>>>>>>
    >>>>>>>> You have a class,
    >>>>>>>>
    >>>>>>>> Class Person
    >>>>>>>> {
    >>>>>>>> public int id;
    >>>>>>>> public string firstname;
    >>>>>>>> public string lastname;
    >>>>>>>> }
    >>>>>>>> when you expose it via webservice,
    >>>>>>>> [WebMethod]
    >>>>>>>> public void UpdatePerson(Person)
    >>>>>>>> {
    >>>>>>>> ...
    >>>>>>>> }
    >>>>>>>> How do I know whether a field value has been specified or not?
    >>>>>>>> For
    >>>>>>>> value
    >>>>>>>> types, there is that matching XXXXSpecified buddy field, but
    >>>>>>>> for
    >>>>>>>> string
    >>>>>>>> type, there doesn't seem to be one.
    >>>>>>>> So if incoming Xml looks something like this:
    >>>>>>>> <Person>
    >>>>>>>> <firstname>Jiho</firstname>
    >>>>>>>> </Person>
    >>>>>>>> when deserialized into a Person object, lastname field will
    >>>>>>>> contain
    >>>>>>>> null, which doesn't tell me whether the field is simply missing
    >>>>>>>> (thus
    >>>>>>>> safely ignored) or lastname field should be set to null (in the
    >>>>>>>> database, for example).
    >>>>>>>> Any idea how to go about this?
    >>>>>>>> Thanks in advance.
    >>>>>>>> Jiho Han
    >>>>>>>> Senior Software Engineer
    >>>>>>>> Infinity Info Systems
    >>>>>>>> The Sales Technology Experts
    >>>>>>>> Tel: 212.563.4400 x216
    >>>>>>>> Fax: 212.760.0540
    >>>>>>>> jhan@infinityinfo.com
    >>>>>>>> www.infinityinfo.com




  10. Default Re: How to tell if a string element is null or really null?

    (Answering my own question) from the w3c rec,

    2.6.2 xsi:nil

    XML Schema: Structures introduces a mechanism for signaling that an element
    should be accepted as ·valid· when it has no content despite a content type
    which does not require or even necessarily allow empty content. An element
    may be ·valid· without content if it has the attribute xsi:nil with the value
    true. An element so labeled must be empty, but can carry attributes if permitted
    by the corresponding complex type.

    which tells me, "nillability" is strictly about the content of an element.
    So in that case, a missing optional element vs. a nillable element which
    possibly can carry attributes, are different.

    btw, in my schema, FirstName would be defined this ways:

    <xs:element name="FirstName" minOccurs="0" nillable="true"/>

    Thanks
    Jiho

    > John,
    >
    > I don't know, you tell me, are these two different?
    >
    > <Person>
    > <FirstName xsi:nil = "true" />
    > <Person>
    > <Person>
    > </Person>
    > Thanks
    >
    >> Is there a difference between the two in the XML InfoSet model?
    >>
    >> John
    >>
    >> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >> news:a19ab9b61bad38c87e27a332ada9@msnews.microsoft.com...
    >>> Hello Kevin,
    >>>
    >>> I am not exactly sure that will help. It doesn't seem to matter how
    >>> the
    >>> SOAP is formatted, the end result is that when the XmlSerializer
    >>> consumes
    >>> an incoming xml, it's same. Once in object form, there is no way to
    >>> tell
    >>> which format it came in.
    >>> This is a bit frustrating. Thanks for your help though.
    >>> Jiho
    >>>> I haven't personally encountered this situation. However, I think
    >>>> that applying some custom formatting to the SOAP XSD might do the
    >>>> trick. See http://msdn2.microsoft.com/en-us/library/k1y9z356.aspx
    >>>>
    >>>> Kevin Spencer
    >>>> Microsoft MVP
    >>>> Professional Chicken Salad Alchemist
    >>>> Sequence, Selection, Iteration.
    >>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>> news:a19ab9b61ba658c87ddbf521dbd8@msnews.microsoft.com...
    >>>>> Kevin,
    >>>>>
    >>>>> I understand that the xml received by the soap endpoint is
    >>>>> different. However, when the xml document is deserialized into an
    >>>>> object, there is no difference - or rather I don't know of a way -
    >>>>> between:
    >>>>>
    >>>>> <Person>
    >>>>> <Lastname xsi:nil = "true"/>
    >>>>> </Person>
    >>>>> vs.
    >>>>> <Person>
    >>>>> </Person>
    >>>>> When it gets deserialized into an object,
    >>>>> Person person = <from soap response>
    >>>>> person.Lastname == null // true for both!
    >>>>> If there is a way to tell the difference, that'd be great. Is
    >>>>> there
    >>>>> some kind of a hook into the soap deserialization scheme?
    >>>>>> An XML document, and in particular, a SOAP document, is not quite
    >>>>>> as simple as you seem to think. It can indicate whether the value
    >>>>>> is null or not. Example:
    >>>>>>
    >>>>>> <SomeObject xsi:nil="true" />
    >>>>>>
    >>>>>> Kevin Spencer
    >>>>>> Microsoft MVP
    >>>>>> Professional Chicken Salad Alchemist
    >>>>>> Sequence, Selection, Iteration.
    >>>>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>>>> news:a19ab9b61b8908c87d39dd555e26@msnews.microsoft.com...
    >>>>>>> Pablo,
    >>>>>>>
    >>>>>>> Perhaps, it is more of a design question...
    >>>>>>>
    >>>>>>> If you want a field to be set to null (think database), how
    >>>>>>> would
    >>>>>>> you
    >>>>>>> specify that from the client side?
    >>>>>>> If you don't include the field, it's null on the server. If you
    >>>>>>> set
    >>>>>>> it to
    >>>>>>> null, it's still null on the server.
    >>>>>>> My point is that there seems to be no way of knowing whether the
    >>>>>>> client
    >>>>>>> intended a field to be set to null vs. skip the field for
    >>>>>>> processing
    >>>>>>> becasue it's missing from the xml.
    >>>>>>> i.e.)
    >>>>>>> <Person>
    >>>>>>> <Lastname>Han</Lastname>
    >>>>>>> <Firstname/>
    >>>>>>> </Person>
    >>>>>>> and
    >>>>>>> <Person>
    >>>>>>> <Lastname>Han</Lastname>
    >>>>>>> </Person>
    >>>>>>> deserializes into an identical object state.
    >>>>>>>> It is as simple as this,
    >>>>>>>>
    >>>>>>>> if( IsNullOrEmpty(person.lastname) )
    >>>>>>>> // Echo Is null
    >>>>>>>> else
    >>>>>>>> // Echo Is not null
    >>>>>>>> That is only valid for string types. For other kind of
    >>>>>>>> reference
    >>>>>>>> type,
    >>>>>>>> you should check if it is equal to null.
    >>>>>>>> if( person.lastname == null)
    >>>>>>>> // Echo Is null
    >>>>>>>> else
    >>>>>>>> // Echo Is not null
    >>>>>>>> "Jiho Han" <jihohan@yahoo.com> wrote in message
    >>>>>>>> news:a19ab9b61a8548c87d1389027fb1@msnews.microsoft.com...
    >>>>>>>>> Here's the issue.
    >>>>>>>>>
    >>>>>>>>> You have a class,
    >>>>>>>>>
    >>>>>>>>> Class Person
    >>>>>>>>> {
    >>>>>>>>> public int id;
    >>>>>>>>> public string firstname;
    >>>>>>>>> public string lastname;
    >>>>>>>>> }
    >>>>>>>>> when you expose it via webservice,
    >>>>>>>>> [WebMethod]
    >>>>>>>>> public void UpdatePerson(Person)
    >>>>>>>>> {
    >>>>>>>>> ...
    >>>>>>>>> }
    >>>>>>>>> How do I know whether a field value has been specified or not?
    >>>>>>>>> For
    >>>>>>>>> value
    >>>>>>>>> types, there is that matching XXXXSpecified buddy field, but
    >>>>>>>>> for
    >>>>>>>>> string
    >>>>>>>>> type, there doesn't seem to be one.
    >>>>>>>>> So if incoming Xml looks something like this:
    >>>>>>>>> <Person>
    >>>>>>>>> <firstname>Jiho</firstname>
    >>>>>>>>> </Person>
    >>>>>>>>> when deserialized into a Person object, lastname field will
    >>>>>>>>> contain
    >>>>>>>>> null, which doesn't tell me whether the field is simply
    >>>>>>>>> missing
    >>>>>>>>> (thus
    >>>>>>>>> safely ignored) or lastname field should be set to null (in
    >>>>>>>>> the
    >>>>>>>>> database, for example).
    >>>>>>>>> Any idea how to go about this?
    >>>>>>>>> Thanks in advance.
    >>>>>>>>> Jiho Han
    >>>>>>>>> Senior Software Engineer
    >>>>>>>>> Infinity Info Systems
    >>>>>>>>> The Sales Technology Experts
    >>>>>>>>> Tel: 212.563.4400 x216
    >>>>>>>>> Fax: 212.760.0540
    >>>>>>>>> jhan@infinityinfo.com
    >>>>>>>>> www.infinityinfo.com




+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Some non-null fields being returned as null?
    By Application Development in forum ADO DAO RDO RDS
    Replies: 1
    Last Post: 08-31-2007, 06:40 AM
  2. XMLHTTP - null is null or not an object
    By Application Development in forum Javascript
    Replies: 0
    Last Post: 06-04-2007, 03:43 AM
  3. Allowing Either a patter or a null value in an Element?
    By Application Development in forum XML SOAP
    Replies: 6
    Last Post: 06-02-2006, 04:21 PM
  4. FOR XML PATH NULL Element
    By Application Development in forum XML SOAP
    Replies: 3
    Last Post: 05-03-2006, 09:04 AM
  5. Suppress Element when Value is NULL in for XML EXPLICIT
    By Application Development in forum XML SOAP
    Replies: 3
    Last Post: 03-23-2006, 06:40 PM