WebService method for passing special characters

Source: Internet
Author: User
Tags cdata

WebService SOAP messages are interactive in XML format, where the delivery of special characters cannot be resolved, resulting in data processing failure.

The workarounds are as follows:

1, before sending the message, the Base64 transcoding for the message, after escaping to avoid the message contains special characters.

The standard Base64, which starts with a%, assumes that it is stored in a database and queried in sql, which resolves to a wildcard character, which results in an error.

After the search using the improved version of Base64 for transcoding, to circumvent the problem, the details of the Niang a bit.

The disadvantage of this approach is that all clients need to know how to decode, otherwise they cannot parse.

2. In XML, it is not good to use CDATA to tag special characters in such a way that they are parsed.

At present, there are 2 shortcomings, one is the need for each of the special characters are converted, first of all I do not know what should be used to join? <! [cdata[]]> is the time when the property value is set, or when the message is last generated;

And using this, the data cannot contain characters such as [[]]. It is troublesome to infer this, and if you know how to solve this problem, please advise me. I am also just a web-learning.


3, still have to study what object of, did not study very much, please everybody discuss what mean:

The XML string is returned to the client via XML Document object, and the XmlDocument cannot be returned to the client directly, because the XML document object in Java cannot be interpreted correctly, we can only return the XML string:
Public String Getallnewspace () {
Document document = Documenthelper.createdocument ();
Element root=document.addelement ("root");
..............................
if (null! = DataSet) {
while (Dataset.next ()) {
Element user=root.addelement ("user");
Element username=user.addelement ("UserName");
Username.settext (dataset.getstring (1));
Element userid=user.addelement ("UserId");
Userid.settext (dataset.getstring (2));
}
}
return Document.asxml ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.