Click here to Skip to main content
15,303,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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="" xmlns:xsd="" xmlns:soap12="">
    <stockcompleteresponse xmlns="">

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

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


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

        Dim root As XmlElement = value.DocumentElement

"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.

1 solution

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:

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

Without CDATA:
This is some HTML code sample: &lt;p&gt;Paragraph&lt;/p&gt;

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".

szataniel 26-Sep-11 14:27pm
You are right... I have to change webmethod and some things in webservice. Thanks for Your support... again. :)
Sergey Alexandrovich Kryukov 26-Sep-11 17:07pm
I'm glad if this helps.
Good luck, call again. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900