473,394 Members | 1,750 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,394 software developers and data experts.

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
jh**@infinityinfo.com
www.infinityinfo.com
Jul 24 '06 #1
13 1115
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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
jh**@infinityinfo.com
www.infinityinfo.com


Jul 24 '06 #2
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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
jh**@infinityinfo.com
www.infinityinfo.com

Jul 24 '06 #3
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsof t.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
jh**@infinityinfo.com
www.infinityinfo.com


Jul 25 '06 #4
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microso ft.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
jh**@infinityinfo.com
www.infinityinfo.com

Jul 25 '06 #5
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsof t.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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.micros oft.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
jh**@infinityinfo.com
www.infinityinfo.com


Jul 25 '06 #6
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microso ft.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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.micro soft.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
>jh**@infinityinfo.com
>www.infinityinfo.com

Jul 25 '06 #7
Is there a difference between the two in the XML InfoSet model?

John

"Jiho Han" <ji*****@yahoo.comwrote in message
news:a1**************************@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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsof t.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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.micros oft.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" <ji*****@yahoo.comwrote in message
>news:a1**************************@msnews.micr osoft.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
>>jh**@infinityinfo.com
>>www.infinityinfo.com


Jul 26 '06 #8
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" <ji*****@yahoo.comwrote in message
news:a1**************************@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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microso ft.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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.micro soft.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" <ji*****@yahoo.comwrote in message
>>news:a1**************************@msnews.mic rosoft.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
>>>jh**@infinityinfo.com
>>>www.infinityinfo.com

Jul 27 '06 #9
(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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsof t.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" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.micros oft.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" <ji*****@yahoo.comwrote in message
>news:a1**************************@msnews.micr osoft.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" <ji*****@yahoo.comwrote in message
>>>news:a1**************************@msnews.mi crosoft.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
>>>>jh**@infinityinfo.com
>>>>www.infinityinfo.com

Jul 27 '06 #10
Jiho Han" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsoft .com...
John,

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

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

<Person>
</Person>
I don't know, either, which is why I asked the question.

They certainly don't appear to be different in the intent of the document
creator.

John
Jul 27 '06 #11
"Jiho Han" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsoft .com...
(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"/>
Ok, so is there a difference to you between a person with no first name, and
a person with ... no first name?

John
Jul 27 '06 #12
Actually, the intention is what you make of it in this case, because I am
the publisher of the schema.

If I am accepting the document for an update method, for example, I could
take the first form as saying set FirstName to null and the second form as
saying, well, nothing. Don't do anything to FirstName at all.

All this to say, the default xml deserialization does not distinguish between
the first and the latter.
I think, though, I can use a custom schema provider for this, then implement
IXmlSerializable on the class so that I can examine the xsi:nil attribute
upon deserializing. We'll see how that goes.
Jiho Han" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsoft .com...
>John,

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

<Person>
<FirstName xsi:nil = "true" />
<Person>
<Person>
</Person>
I don't know, either, which is why I asked the question.

They certainly don't appear to be different in the intent of the
document creator.

John

Jul 27 '06 #13
You could also try changing the schema to include the two alternatives
clearly specified. You could, for instance, create a global "doNotTouch"
attribute, and use it on the <FirstNameor wherever else. The sender could
explicitly indicate what he wants to do, and this question of similarities
would be moot.

John
"Jiho Han" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsoft .com...
Actually, the intention is what you make of it in this case, because I am
the publisher of the schema.

If I am accepting the document for an update method, for example, I could
take the first form as saying set FirstName to null and the second form as
saying, well, nothing. Don't do anything to FirstName at all.

All this to say, the default xml deserialization does not distinguish
between the first and the latter.
I think, though, I can use a custom schema provider for this, then
implement IXmlSerializable on the class so that I can examine the xsi:nil
attribute upon deserializing. We'll see how that goes.
>Jiho Han" <ji*****@yahoo.comwrote in message
news:a1**************************@msnews.microsof t.com...
>>John,

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

<Person>
<FirstName xsi:nil = "true" />
<Person>
<Person>
</Person>
I don't know, either, which is why I asked the question.

They certainly don't appear to be different in the intent of the
document creator.

John


Jul 29 '06 #14

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

Similar topics

10
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of...
22
by: bmgz | last post by:
sorry for the stupid question, bu6 I haven't been able to find the answer anywhere.. consider this useless function which assigns an object to a var.. function(myParam){ var select1 =...
16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
13
by: Jiho Han | last post by:
Here's the issue. You have a class, Class Person { public int id; public string firstname; public string lastname; }
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
1
thatos
by: thatos | last post by:
When I run this program import au.id.jericho.lib.html.*; import java.util.*; import java.io.*; import java.net.*; public class DisplayAllElements { public static void main(String args)...
2
by: Joah Senegal | last post by:
Hello all, I;m a beginner with XML. All I want is to print the XML string with tags. In the following example, there is function called: xmlNodeGetString. This function is getting a char* back....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.