我该如何区分空标签和缺失标签 [英] How can I difference between an empty tag and a missing tag

查看:64
本文介绍了我该如何区分空标签和缺失标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WCF的新手.我有一个Web服务,目的是更新数据库表中的某些字段.发送到Web服务中的XML包含很多标记,这些标记指向表中所有可能更新的字段.但是由于用户 在某些情况下,Web服务仅想更新一些字段,而不要更新其余字段,我需要一种方法来了解用户对Web服务的意图.在我看来,如果用户省略了标签,则该字段不会更新是合理的. 如果标签存在,即使字段为空,我们也会将该字段更新为该值(为null).但是在WCF进行的反序列化中,似乎该字段始终为null.因此,某些数据不是用户的意图而被覆盖.有人有

I'm a new beginner in WCF. I have a webservice which purpose is to update some fields in a database table. The XML that is sent into the webservice contains a lot of tags to all the fields that are possible to update in the table. But since the user of the webservice in some cases only would like to update a few of the fields and not update the rest, I need a way of knowing what intention the user had of the webservice had. To me it seems reasonable that if the user omits the tag the field is not updated. If the tag is present we update the field to the value even if it is empty (to null). But in the dereialization made by WCF it seems as the field always gets a null. Thereby some data is overwritten which was not the intention by the user. Does someone have a solution to this problem?

推荐答案

序列化/反序列化的工作方式如下:

Serialization/Deserialization works as:

  • < Tag></Tag> -String.Empty
  • < Tag/>  -String.Empty
  • 无节点-Null
  • < Tag xsi:nil ="true" /> -空使该值为Null是一个特殊的属性.
  • <Tag></Tag> - String.Empty
  • <Tag />  - String.Empty
  • no node - Null
  • <Tag xsi:nil="true" /> - Null   It is a special attribute to make the value is Null.

但无节点"表示案例确实取决于服务与客户之间的约定.在Xml或Xsd标准中对此没有描述.

But the "no node" case is really up to convention between service and clients. No description of this in the Xml or Xsd standards.


这篇关于我该如何区分空标签和缺失标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆