功能:
public string getAccomodationspattern2(string AccomodationID)
{
SqlCommand cmd = new SqlCommand("XML_AccommodationsDetail_V4", con);
cmd.Parameters.AddWithValue("@AccommodationID", AccomodationID);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int j = 0; j < dt.Rows.Count; j++)
{
for (int k = 0; k < dt.Columns.Count; k++)
{
Response += dt.Rows[j][k].ToString();
}
}
//StringBuilder output = new StringBuilder();
//XmlReader rawData = XmlReader.Create(new StringReader(Response));
//XmlWriterSettings writerSettings = new XmlWriterSettings();
//writerSettings.OmitXmlDeclaration = true;
//using (XmlWriter transformedData = XmlWriter.Create(output, writerSettings))
//{
// XslCompiledTransform transform = new XslCompiledTransform();
// transform.Load(HttpContext.Current.Server.MapPath("getaccommodation2.xslt"));
// transform.Transform(rawData, transformedData);
// return output.ToString();
//}
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(HttpContext.Current.Server.MapPath("getaccommodation2.xslt"));
StringWriter results = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(Response)))
{
transform.Transform(reader, null, results);
}
return results.ToString();
//XDocument xdoc = new XDocument(results.ToString());
//return xdoc.Root;
}
调用函数:
[OperationContract]
[WebGet(UriTemplate = "/AccommodationsBookingPattern/getAccommodations?id={AccomodationID}",
BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
string getAccomodationspattern2(string AccomodationID);
问题是我收到这样的输出:
我现在得到的 XML 文件输出:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
<result><Address></Address><checkin><from>00:30</from><to>01:15</to></checkin><city>London</city><city_id>1</city_id><Location><Latitude>13131313</Latitude><Longitude>11131131</Longitude></Location><city_id>1</city_id><max_persons_in_reservation>1000</max_persons_in_reservation><name>Tahir Hotel</name><ranking>1</ranking><url>123Testing</url><zip>W2 6DX</zip></result><result><Address></Address><checkin><from>00:30</from><to>01:15</to></checkin><city>London</city><city_id>1</city_id><Location><Latitude>13131313</Latitude><Longitude>11131131</Longitude></Location><city_id>1</city_id><max_persons_in_reservation>1000</max_persons_in_reservation><name>Tahir Hotel</name><ranking>1</ranking><url>123Testing</url><zip>W2 6DX</zip></result><result>
问题
我想要正确的标签,我可以打开结果地址标签并以 xml 形式关闭。请帮助我将不胜感激