【发布时间】:2012-07-04 06:01:39
【问题描述】:
我目前有一个程序可以将数据从 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# 中遇到错误,因为它无法解析与号 (&)。
【问题讨论】:
-
你想将 & 编码为 &使用 Server.HtmlEncode & Server.HtmlDecode
-
在你的 XML 中有问题的 & 符号在哪里?你能展示 XML 的那部分吗?