WP7 WebBrowser Control's NavigateToString is not displaying html data - windows-phone-7

I am working on the WebBrowser control in WP7 This is the sample HTML I wrote and asked the webBrowser to navigate To String than its working fine but when i stored this html in to variable and asked to navigate To String than out put is html format.My HTML string was came from web service so i am not able to pass direct string.
my C# code is:
JObject cityblog1 = (JObject)cityblog[0];
string cityimg = (string)cityblog1["CityImage"];
string citydetail = (string)cityblog1["CityDetail"];
City_Blog cb = new City_Blog();
cb.CityImage = cityimg;
cb.CityDetail = citydetail;
lstcityblogdetail.Add(cb);
setimg();
//"\u003cbody style=\"text-align:justify\"\u003e\u003cp\u003e\r\n\tname\u003c/p\u003e\r\n\u003cp\u003e\r\n\t\u003ca href=\"36\" style=\"color: red\"\u003emovieplex\u003c/a\u003e\u003c/p\u003e\r\n\u003cp\u003e\r\n\t\u003ca href=\"47\" style=\"color: red\"\u003etest\u003c/a\u003e\u003c/p\u003e\r\n\u003c/body\u003e"
webBrowser1.NavigateToString(citydetail);
see this string is came from web service when i pass this String than its give right output but when i strored this string in to citydetail variable and pass than it give output on html formate.
How can i solve this problem give some instruction.

To remove nbsp; use this citydetail.Replace("nbsp;","");. You can also learn about using Regex Expressions according to your application.

Related

Google Doc Api : download inline object

I'm creating a Google Doc to HTML converter, I want to use the Doc Api and not export it as HTML using the Drive Api :
$service = new Google_Service_Docs($client);
$request = $service->documents->get($docId);
$elements = $request->getBody()->getContent();
$elements is an array of Google_Service_Docs_StructuralElement
Looping through paragraph > elements, if there is an inline object, the inlineObjectElement property is set with a Google_Service_Docs_InlineObjectElement
Question is : how to get the content of an Google_Service_Docs_InlineObjectElement to save it as a file ?
All we have in this object is an inlineObjectId...
I was able to find a solution for this on this blog post.
Basically, all inline elements are located at:
$inlineObjects = $request->getInlineObjects();
Btw. I recommend renaming "$request" to "$document"
Now, with the inlineObjectId you can get the particular object you want - and there, you get a contentUri which contains the binary content.
Here, a screenshot of $inlineObjects contents, which is an assoc array. The key is the inlineObjectId:

From Google Maps CID to Place ID

I have a bunch of links to google maps in the form of https://maps.google.com/?cid=<identifier>.
How can you go from that CID to a Place ID that can be used with the Google Places API? Is there any API endpoint that you can use to convert these URLs into the new places?
Got lucky and found an undocumented api. If you have the CID, you can call the api like https://maps.googleapis.com/maps/api/place/details/json?cid=${CID}&key=YOUR_API_KEY.
I just changed place_id=${the_end_val_i_needed} to cid=${CID} and in the json response is the place_id.
You can use this API hidden parameter to get Place ID. Usage: https://maps.googleapis.com/maps/api/place/details/json?cid=YOUR_CID&key=YOUR_KEY
It returns a result contains formatted address, place_id, name of the address and GPS coordinater.
Please see my blog to see more detail: https://leonbbs.blogspot.com/2018/03/google-map-cid-to-placeid-or-get.html
The only way that I am aware of is scraping the regular html response. This can change of course at any time at Googles discretion and I would be interested in a better solution as well.
As of now e.g. the source of http://maps.google.com/?cid=15792901685599310349 has a json response embedded. It starts with cacheResponse([[[ and ends with ]);:
<!DOCTYPE html>
<html dir=ltr>
<head>
<script nonce="W6BFnVsL4HLAdFCwYXZY">
mapslite = {
START_PERF: (window.performance && window.performance.now) ?
window.performance.now() : +(new Date())
};
mapslite.getBasePageResponse = function(cacheResponse) {
delete mapslite.getBasePageResponse;
cacheResponse([[[2556.225486744883,-122.3492774,47.6205063], ... removed ... ]);
};
executeOgJs = function() {
Within this json array element 8 contains a sub array. Element 27 is the place_id.
In case of the Space Needle with CID 15792901685599310349 the place id is ChIJ-bfVTh8VkFQRDZLQnmioK9s.
Only Google knows why they don't provide a better way.

HtmlAgilityPack sanitizing string issue

I'm using HtmlAgilityPack to sanitize user entered rich text and strip any harmful/unwanted text. Problem occurs though when a simple text is also treated as html node
If I enter
a<b, c>d
and try to sanitize it, the output generated is
a<b, c="">d</b,>
The code I used was
HtmlDocument doc = new HthmlDocument();
doc.LoadHtml(value);
// Sanitizing Logic
var result = doc.DocumentNode.WriteTo();
I tried to set different parameters on HtmlDocument ('OptionCheckSyntax', 'OptionAutoCloseOnEnd', 'OptionWriteEmptyNodes') to not have the text be treated as a node but nothing worked. Is this is a known issue or any workaround possible?
IMO, there's no way you can tell HAP to not treat every '<' as start of new html node. But you can check if your html is a validate html or not by using
string html = "your-html";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
if (doc.ParseErrors.Count() > 0)
{
//here you can ignore or do whatever you want
}

MSXML2.DOMDocument.xml give me malformed xml

We have an old legacy system that where a component is writter in VB6. One method returns a string that is xml data. The xml data is created with msxml3.dll MSXML2.DOMDocument and returns the data of the document with the property xml: http://msdn.microsoft.com/en-us/library/ms755989(v=VS.85).aspx
However, some data of the xmldocument is from the database and one field is a hashed password string. The code that set the data for the element:
Set cellNode = rowNode.appendChild(xml.createElement("COL"))
If IsNull(rs(oField.name).Value) Then
cellNode.Text = ""
Else
cellNode.Text = rs(oField.name).Value
End If
This gives me malformed/non-wellformed xml:
<ROWS><ROW><COL>r<í</COL></ROW></ROWS>
Is there a workaround for this?
You should escape unicode characters. Or put them in a CDATA tag (which is not such a nice solution though)
Btw < > and & should be escaped as well.

Image tag not closing with HTMLAgilityPack

Using the HTMLAgilityPack to write out a new image node, it seems to remove the closing tag of an image, e.g. should be but when you check outer html, has .
string strIMG = "<img src='" + imgPath + "' height='" + pubImg.Height + "px' width='" + pubImg.Width + "px' />";
HtmlNode newNode = HtmlNode.Create(strIMG);
This breaks xhtml.
Telling it to output XML as Micky suggests works, but if you have other reasons not to want XML, try this:
doc.OptionWriteEmptyNodes = true;
Edit 1:Here is how to fix an HTML Agilty Pack document to correctly display image (img) tags:
if (HtmlNode.ElementsFlags.ContainsKey("img"))
{ HtmlNode.ElementsFlags["img"] = HtmlElementFlag.Closed;}
else
{ HtmlNode.ElementsFlags.Add("img", HtmlElementFlag.Closed);}
replace "img" for any other tag to fix them as well (input, select, and option come up frequently). Repeat as needed. Keep in mind that this will produce rather than , because of the HAP bug preventing the "closed" and "empty" flags from being set simultaneously.
Source: Mike Bridge
Original answer:
Having just labored over solutions to this issue, and not finding any sufficient answers (doctype set properly, using Output as XML, Check Syntax, AutoCloseOnEnd, and Write Empty Node options), I was able to solve this with a dirty hack.
This will certainly not solve the issue outright for everyone, but for anyone returning their generated html/xml as a string (EG via a web service), the simple solution is to use fake tags that the agility pack doesn't know to break.
Once you have finished doing everything you need to do on your document, call the following method once for each tag giving you a headache (notable examples being option, input, and img). Immediately after, render your final string and do a simple replace for each tag prefixed with some string (in this case "Fix_", and return your string.
This is only marginally better in my opinion than the regex solution proposed in another question I cannot locate at the moment (something along the lines of )
private void fixHAPUnclosedTags(ref HtmlDocument doc, string tagName, bool hasInnerText = false)
{
HtmlNode tagReplacement = null;
foreach(var tag in doc.DocumentNode.SelectNodes("//"+tagName))
{
tagReplacement = HtmlTextNode.CreateNode("<fix_"+tagName+"></fix_"+tagName+">");
foreach(var attr in tag.Attributes)
{
tagReplacement.SetAttributeValue(attr.Name, attr.Value);
}
if(hasInnerText)//for option tags and other non-empty nodes, the next (text) node will be its inner HTML
{
tagReplacement.InnerHtml = tag.InnerHtml + tag.NextSibling.InnerHtml;
tag.NextSibling.Remove();
}
tag.ParentNode.ReplaceChild(tagReplacement, tag);
}
}
As a note, if I were a betting man I would guess that MikeBridge's answer above inadvertently identifies the source of this bug in the pack - something is causing the closed and empty flags to be mutually exclusive
Additionally, after a bit more digging, I don't appear to be the only one who has taken this approach:
HtmlAgilityPack Drops Option End Tags
Furthermore, in cases where you ONLY need non-empty elements, there is a very simple fix listed in that same question, as well as the HAP codeplex discussion here: This essentially sets the empty flag option listed in Mike Bridge's answer above permanently everywhere.
There is an option to turn on XML output that makes this issue go away.
var htmlDoc = new HtmlDocument();
htmlDoc.OptionOutputAsXml = true;
htmlDoc.LoadHtml(rawHtml);
This seems to be a bug with HtmlAgilityPack. There are many ways to reproduce this, for example:
Debug.WriteLine(HtmlNode.CreateNode("<img id=\"bla\"></img>").OuterHtml);
Outputs malformed HTML. Using the suggested fixes in the other answers does nothing.
HtmlDocument doc = new HtmlDocument();
doc.OptionOutputAsXml = true;
HtmlNode node = doc.CreateElement("x");
node.InnerHtml = "<img id=\"bla\"></img>";
doc.DocumentNode.AppendChild(node);
Debug.WriteLine(doc.DocumentNode.OuterHtml);
Produces malformed XML / XHTML like <x><img id="bla"></x>
I have created a issue in CodePlex for this.

Resources