如何从Web API返回CDATA部分

时间:2016-07-29 12:52:30

标签: xml vb.net api rest cdata

使用vb.net,Web API将在定义的类的相同结构中返回XML:

Public Class Human
   Public Property Name As String = ""
   Public Property Height As String = ""
   Public Property Age As String = ""
   Public Property Sex As String = ""
End Class

因此,API会返回Human类型,并会给出类似的结果,因为类定义了xml结构:

<Human>
   <Name>Bill</Name>
   <Height>129cm</Height>
   <Age>32</Age>
   <Sex>Male</Sex>
</Human>

是否可以以相同的方式返回CDATA部分?

我尝试将类中的一个属性声明为:

Public Class Human
   Public Property Name As String = ""
   Public Property Height As String = ""
   Public Property Age As String = ""
   Public Property Sex As String = ""
   Public Property Details As System.Xml.Linq.XCData
End Class

然后尝试像这样填充它:

Dim Result As New Human

Result.Details = New System.Xml.Linq.XCData("text here")

但是当我调用该操作时,我没有得到任何数据,所以我认为我在这里做了一些非常错误的事情。

我也尝试过以这种方式设置数据:

Dim temp As System.Xml.Linq.XCData = <![CDATA[text here]]>
Result.Details = temp

0 个答案:

没有答案