对于声明为 nillable 的字段,我应该发送什么 XML? [英] What XML do I send for a field thats declared as nillable?

查看:27
本文介绍了对于声明为 nillable 的字段,我应该发送什么 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 REST 风格界面的应用程序,它通过 POST 从客户端获取 XML 文档.该应用程序是用 Java 编写的,并使用 XML bean 来处理发布的消息.

I have an application with a REST style interface that takes XML documents via POST from clients. This application is written in Java and uses XML beans to process the posted message.

消息中字段的 XML 架构定义如下所示:

The XML schema definition for a field in the message looks like this:

<xs:element name="value" type="xs:string" nillable="true" />

如何发送符合此规范的空值?

How do I send a null value that meets this spec?

我发送了 但这导致 XML 解析器停止运行.

I sent <value xsi:nil="true" /> but this caused the XML parser to barf.

推荐答案

这是发送 nil 值的正确方式(假设默认命名空间和 xsi 命名空间设置为正确的值,即 "http://www.w3.org/2001/XMLSchema-instance" for xsi.) 所以看起来你可能遇到了您正在使用的 CML 解析器.错误信息是什么?

That's the right way of sending a nil value (assuming that the default namespace and the xsi namespace are set to the correct values, namely "http://www.w3.org/2001/XMLSchema-instance" for xsi.) so it looks like you might have come up against a bug in the CML parser you're using. What's the error message?

您可以尝试使用 xsi:nil="1" 或使用单独的开始和结束标记(</value>) 尝试解决该错误.

You might try using xsi:nil="1" or using separate open and close tags (<value xsi:nil="true"></value>) to try working around the bug.

这篇关于对于声明为 nillable 的字段,我应该发送什么 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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