我目前有一个程序可以将数据从VBA(Access)转移到C#(通过ASP.NET POST)。我如何在每一端编码/解码?
这是我在C#中读取的XML:
StreamReader reader = new StreamReader(Request.InputStream);
string xmlData = "";
XmlDocument xml = new XmlDocument();
xmlData = reader.ReadToEnd();
XmlElement rootXML;
xml.LoadXml(xmlData);
rootXML = xml.DocumentElement;
这是我用C#编写的XML:
Response.Clear();
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";
Response.Write(XML_in_String);
Response.End();
这是我在VBA中的XML写入
connection.Open "POST", server & "www.webpage.com/" & postData, False
connection.setRequestHeader "Accept", "application/xml"
connection.setRequestHeader "Content-Type", "application/xml"
connection.send "<?xml version=""1.0"" encoding=""UTF-8"" ?><data>" & outXMLstr & "</data>"
这是我在VBA中的XML读取
Dim inXML As MSXML2.DOMDocument
Set inXML = New DOMDocument
inXML.loadXML (connection.responseText)
具体来说,我在尝试加载XML(xmlData)时遇到了C#错误,因为它无法解析&符号(&amp;)。
答案 0 :(得分:1)
在xmlData
上,您是否尝试过@HatSoft说,使用Server.HtmlEncode
/ Server.HtmlDecode
?这样你就可以摆脱那些在XML中不起作用的能力。
或者您可以将数据包装到CDATA字段