xml CDATA部分-如何通过Web服务仅发送CDTATA [英] xml CDATA section - how to send only CDTATA through webservice

查看:423
本文介绍了xml CDATA部分-如何通过Web服务仅发送CDTATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我通过网络服务发送xml CDATA部分存在严重问题.

在适当的部分中,我有将方法女巫发送xml到SOAP的方法:

Hello,

I have a serious problem with sending xml CDATA section through web service.

I have method witch sending xml to SOAP in proper section:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length


<soap12:envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:body>
    <stockcompleteresponse xmlns="http://xxx.com/">
      <stockcompleteresult>xml</stockcompleteresult>
    </stockcompleteresponse>
  </soap12:body>
</soap12:envelope>



在此代码的第7行中,应仅将XML与CDATA部分一起放置.我已经在服务器方法(vb.net)上使用代码构建了该XML:



In line 7 of this code should be placed XML with CDATA section only. I have built this XML with code on server method (vb.net):

Dim builder As New StringBuilder
       
        builder.Append("<stockinfo>")
        For Each dr As DataRow In ds.Tables(0).Rows
            builder.Append("<product>")
            builder.Append("<productid>" & dr.Item("PRODUCTID") & "</productid>")
            builder.Append("<stock>" & dr.Item("STOCK") & "</stock>")
            builder.Append("</product>")
        Next
        builder.Append("</stockinfo>")

        value.LoadXml("<stock></stock>")

        Dim CData As XmlCDataSection
        CData = value.CreateCDataSection(builder.ToString())

        Dim root As XmlElement = value.DocumentElement
        root.AppendChild(CData)



值"是XMLDocument数据类型,整个函数返回XMLDocument.

我知道这种构建xml的方法很好,因为在调用webservice时我得到了正确的xml,但是我的客户端看到了错误消息.原因很简单:将根放在返回的xml中.
所以我的问题是:如何在不使用root的情况下仅发送XML中的CDATA节?有可能吗?
我已经尝试过使用字符串数据类型,但是后来我也看到了错误消息.



"value" is XMLDocument datatype and whole function returns XMLDocument.

I know that this method of building xml is good, because i get proper xml when calling webservice, but my client see error message. The reason is simple: root in returned xml.
So my question is: how to send only CDATA section in XML without root? Is it possible?
I''ve tried with string datatype, but then I see error message too.

推荐答案

我认为您的问题不是XML编程问题,而是概念性问题.关键是:CDATA部分不是XML逻辑结构的一部分.从逻辑结构的角度来看,这种东西根本不存在. CDATA只是一种表达工具,用于输入包含XML标记字符的字符数据.

考虑以下两个XML代码示例:

使用CDATA:
I think your problem is not a problem of XML programming, but a conceptual one. The thing is: CDATA section is not a part of XML logical structure. From the logical structure perspective, such thing simply does not exist. CDATA is merely an expressive tool used to enter character data containing XML markup characters.

Consider these two XML code samples:

With CDATA:
<rootNode>
<![CDATA[This is some HTML code sample: <p>Paragraph</p>]]>
</rootNode>



没有CDATA:



Without CDATA:

<rootNode>
This is some HTML code sample: &lt;p&gt;Paragraph&lt;/p&gt;
</rootNode>



例如,当这些片段由标准XML解析器解析为DOM结构时,就找不到它们之间的区别.从逻辑结构的角度来看,它们是相同的.第一个示例使用CDATA,第二个示例使用XML 字符实体.两种方法都用于转义" XML标记字符"<"和">"; CDATA只是写同一件事的一种较短的方法.两者都与逻辑结构无关.他们根本不必发送".

—SA



When these fragments are parsed by a standard XML parser, for example, into DOM structure, no difference between them can be found. From the standpoint of logical structure, they are the same. First sample uses CDATA, second one — XML character entities. Both methods are used to "escape" XML markup characters ''<'' and ''>; CDATA is simply a shorter way to write the same thing. Both have nothing to do with logical structure. They simply don''t have to be "sent".

—SA


这篇关于xml CDATA部分-如何通过Web服务仅发送CDTATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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