我该如何区分空标签和缺失标签

编程入门 行业动态 更新时间:2024-10-10 09:14:31
本文介绍了我该如何区分空标签和缺失标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是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 thisin the Xml or Xsd standards.

更多推荐

我该如何区分空标签和缺失标签

本文发布于:2023-11-06 03:33:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562622.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   我该   缺失

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!