问题是这样的,公司内部服务器之间数据传输协议时xml,我现在需要用serverA请求serverB,发送用户注册邮件,邮件模板里面有html代码,serverB在收到请求数据后,由于html中有<、>等特殊符号的缘故,导致xml无法解析,一时不知道怎么办,各位有解决办法木有?
如果在发送端不对html代码进行任何处理,接收到解析就会异常:
[Fatal Error] :1:1: Content is not allowed in prolog.
<![CDATA[ Insert your HTML code here. Standard-compliant HTML code will not have the XML CDATA terminator. ]]>
Characters such as > < & must be escaped when used in the body or attributes of xml, please search for "xml escape" + your language
Try BASE64.
酷壳有个答案 http://coolshell.cn/articles/3498.html。虽然像是笑话,不过确实是那么回事:
<!-- ED: soap envelope omitted for readability --> <string xmlns="urn:Initech.Global.Services"> <CompanyGetConnector> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="InitechGetConnector"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="employees"> <xs:complexType> <xs:sequence> <xs:element name="EmployerName" type="xs:string" minOccurs="0"/> <xs:element name="Employee" type="xs:string" minOccurs="0"/> <xs:element name="Firstname" type="xs:string" minOccurs="0"/> <xs:element name="Prefix" type="xs:string" minOccurs="0"/> <xs:element name="Lastname" type="xs:string" minOccurs="0"/> <xs:element name="Org._unit" type="xs:string" minOccurs="0"/> <xs:element name="Function" type="xs:string" minOccurs="0"/> <xs:element name="E-mail_work" type="xs:string" minOccurs="0"/> <xs:element name="Telephone_work" type="xs:string" minOccurs="0"/> <xs:element name="Mobile_work" type="xs:string" minOccurs="0"/> <xs:element name="Birthdate" type="xs:date" minOccurs="0"/> <xs:element name="Hired_since__irt._yearsemployed_" type="xs:date" minOccurs="0"/> <xs:element name="Image" type="xs:base64Binary" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <employees> <EmployerName> My Client </EmployerName> <Employee> 100001 </Employee> </employees> </CompanyGetConnector> </string>
Characters such as > < & must be escaped when used in the body or attributes of xml, please search for "xml escape" + your language
Try BASE64.
酷壳有个答案 http://coolshell.cn/articles/3498.html。虽然像是笑话,不过确实是那么回事: