I am trying to generate an API who returns info in xml format. When using the proper URL the XmlDocument is being generated properly but I have problems to show it and send it back. For example in http://ift.tt/JqqdUC if I select a place I get the info and I can see it in the browser in a nice XML document.
<GeocodeResponse>
<status>OK</status>
<result>
<type>street_address</type>
<formatted_address>277 Bedford Avenue, Brooklyn, NY 11211, EE. UU.</formatted_address>
<address_component>
<long_name>277</long_name>
<short_name>277</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>Bedford Avenue</long_name>
<short_name>Bedford Ave</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Williamsburg</long_name>
<short_name>Williamsburg</short_name>
<type>neighborhood</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Brooklyn</long_name>
<short_name>Brooklyn</short_name>
<type>sublocality_level_1</type>
<type>sublocality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Kings County</long_name>
<short_name>Kings County</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>New York</long_name>
<short_name>NY</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Estados Unidos</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>11211</long_name>
<short_name>11211</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>40.7142320</lat>
<lng>-73.9612889</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>40.7128830</lat>
<lng>-73.9626379</lng>
</southwest>
<northeast>
<lat>40.7155810</lat>
<lng>-73.9599399</lng>
</northeast>
</viewport>
</geometry>
<place_id>ChIJd8BlQ2BZwokRAFUEcm_qrcA</place_id>
</result>
This is exactly what I want to make. I tried using the following once I generate the Xml document:
Response.ContentType = "text/xml"; //must be 'text/xml'
Response.ContentEncoding = System.Text.Encoding.UTF8; //we'd like UTF-8
XmlDoc.Save(Response.Output);
The result is not appearing and if I check in the browser console I see the following:
<car Acrisscode="XVDMR" Description="<![CDATA[]]>" Capacity="5" Price="199,5" IncludedDistance="0" IncludedDistanceUnit="K" IncludedDistanceType="D" ExtraDistancePrice="0.15" AptTax="0" AppTaxIncluded="U" YoungDrvFee="0" YoungDrvFeeIncluded="Y" FuelPolicy="U" Supplier="Social Car" Pickup="<![CDATA[Carrer John Lennon]]>" Dropoff="<![CDATA[Carrer John Lennon]]>" Image="/9_13_perfil.jpg" Deep_link="<![CDATA[Carrer John Lennon]]>"/>
And also the following:
var stringWriter = new StringWriter();
var xmlTextWriter = XmlWriter.Create(stringWriter);
XmlDoc.WriteTo(xmlTextWriter);
xmlTextWriter.Flush();
string result = stringWriter.GetStringBuilder().ToString();
saveText.Text = result; //saveText is the ID of a Label
But the result is still the same...
Here is how I created the xml:
XmlDocument XmlDoc = new XmlDocument();
XmlDeclaration XmlDecl;
XmlDecl = XmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "");
XmlDoc.AppendChild(XmlDecl);
XmlElement RootElem = XmlDoc.CreateElement("cars");
XmlDoc.AppendChild(RootElem);
if (result.Count > 0)
{
XmlElement xmlMarker;
foreach (VehiculoResult item in result)
{
if (!(int.Parse(driver_age) < 21 && item.TipoSeguro == 2))
{
string accris = CreateAccriscode(item);
xmlMarker = XmlDoc.CreateElement("car");
RootElem.AppendChild(xmlMarker);
xmlMarker.SetAttribute("Acrisscode", accris);
xmlMarker.SetAttribute("Description", "<![CDATA[" + item.Descripcion + "]]>");
xmlMarker.SetAttribute("Capacity", item.NumPlazas.ToString());
DateTime fechaInicio = DateTime.Parse(pickup_date + " " + pickup_time);
DateTime fechaFin = DateTime.Parse(dropoff_date + " " + dropoff_time);
double price = UtilesReserva.ObtenerImporteReserva(TimeSpan.Parse((fechaFin - fechaInicio).ToString()),
item.PrecioHora, item.PrecioDia,
item.PrecioSemana, item.PrecioMes);
if (item.TipoSeguro == 2)
{
price += wService.CalcularPrecioSeguro(fechaInicio, fechaFin);
}
xmlMarker.SetAttribute("Price", price.ToString());
if (item.LimitacionKM == 1)
{
xmlMarker.SetAttribute("IncludedDistance", "250");
}
else if (item.LimitacionKM == 2)
{
xmlMarker.SetAttribute("IncludedDistance", "500");
}
else
{
xmlMarker.SetAttribute("IncludedDistance", "0");
}
xmlMarker.SetAttribute("IncludedDistanceUnit", "K");
xmlMarker.SetAttribute("IncludedDistanceType", "D");
xmlMarker.SetAttribute("ExtraDistancePrice", "0.15");
xmlMarker.SetAttribute("AptTax", "0");
xmlMarker.SetAttribute("AppTaxIncluded", "U");
xmlMarker.SetAttribute("YoungDrvFee", "0");
xmlMarker.SetAttribute("YoungDrvFeeIncluded", "Y");
xmlMarker.SetAttribute("FuelPolicy", "U");
xmlMarker.SetAttribute("Supplier", "Social Car");
xmlMarker.SetAttribute("Pickup", "<![CDATA[" + item.Direccion + "]]>");
xmlMarker.SetAttribute("Dropoff", "<![CDATA[" + item.Direccion + "]]>");
xmlMarker.SetAttribute("Image", item.UrlFotoPerfil);
xmlMarker.SetAttribute("Deep_link", "<![CDATA[" + item.Direccion + "]]>");
}
}
}
Anyone knows what I am missing or doing wrong?
No comments:
Post a Comment