I have use web service in my windows application. webservice return string like:
<b>sdfsdf</b>
<img alt="*" src="df"/>
is any way in windows form that read html tag. like if <b/> then text is bold. and <img/> image should apear not text.
Easiest way would be to use a WebBrowser control, I suppose.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx
Load your XML string into an XmlDocument:
XmlDocument doc = new XmlDocument();
doc.LoadXml(webservice_output_string);
Then you can use XPath against the document:
string bold = (doc.SelectSingleNode("//b") as XmlElement).InnerText;
string src = (doc.SelectSingleNode("//img/#src") as XmlAttribute).Value;
Related
I am attempting to retrieve and store text from a Sub Header element on a web page.
The HTML from the page is as follows:
<h5 class="page-sub-header-com page-sub-header-subtext">Customer #8107 - NGP_APPLICATION_017</h5>
I would just like to retrieve the text "Customer #8107 - NGP_APPLICATION_017".
Thanks in Advance
This should be very easy with cssSelector
By css = By.CssSelector("h5.page-sub-header-com.page-sub-header-subtext");
string element = Driver.FindElement(css).Text;
Solution provided by Saifur
By css = By.CssSelector("h5.page-sub-header-com.page-sub-header-subtext");
string element = Driver.FindElement(css).Text;
I'm creating a universal app and need to be able to pull plain text from a HTML page. I know that in WPF you can utilize the IHTMLDocument2 interface to achieve this.
IHTMLDocument2 document = webBrowser1.Document as IHTMLDocument2;
string data = document.body.innerText;
Is there something similar for Windows Runtime?
Thanks,
I would use something like HtmlAgilityPack. The HTML then becomes queryable through Linq. Then you can do something like this:
HtmlDocument htmlDoc = webBrowser1.Document as HtmlDocument;
string innerText = htmlDoc.DocumentNode.Descendants("body").Single().InnerText;
You can also load the HTML as a string or stream through LoadHtml and Load respectively.
I have my XML as a string and need to display it in a div
I have searched all the ways to format an XML, but it doesn't work as I am finally binding my contents to a div.
Following is what I am using in my asp.net applicaion c# code.
request = //my xml string
XDocument doc = XDocument.Parse(request);
divLogResults.InnerText = doc.ToString()
I have tried all the ways listed here as well
What is the simplest way to get indented XML with line breaks from XmlDocument?
So this isn't a duplicate. How can I do this in a simple way ?
Bind your XML content in a text area. I think this should work.
Web form:
<textarea rows="20" cols="40" style="border:none;" runat="server" id="txtXML" readonly="true">
</textarea>
Code behind:
request = // xml string
XDocument doc = XDocument.Parse(request);
txtXML.Text = doc.ToString()
Please make sure your xml content has the header appended
e.g.,
<?xml version="1.0" encoding="ISO-8859-1"?>
I have some HTML which is encoded as XML, for example:
html = "this is a test </a> test <em>test2</em> ... "
So when I try to load this into a WebView control, it doesn't correctly render the HTML:
myWebView.NavigateToString(html);
Just to be clear, I am not creating this HTML in this fashion, but am stuck with it. Is there a way to either render this to the control, or convert it to standard HTML first?
string html = HttpUtility.HtmlDecode("this is a test </a> test <em>test2</em> ... ");
I have a C# Form with WebBrowser object.
This object contains HTML Document.
And there is a link in that document that has no markers (no id and no name)
How can I access this element??
I tried to use this:
webBrowser1.Document.GetElementsByTagName("a")[n]
But it is not very useful, because if there will be some new link on the page, I'll need to rebuild all program.
I also can not do loops through document, or get a substring of Document.ToString() because then I can not click the link.
Would be great if you could give me some advice.
In this kind of situation the best idea is always to find an "Anchor", meaning - a place in the document that never change.
Lets say that
dada
Doesn't have an ID or Name, so the closest you can go is check if the parent of the element you're looking for has an ID.
<div id="parentDiv">
Some text
Some other stuff
The link you're looking for
</div>
That way you could get the parentDiv, which you know doesn't change, and then the A tag inside that parent (which should be permanent unless that website completely changes the structure which is one of the problems in parsing external HTML pages)
Shai.
you can use Html Agility Pack. and select links by xpath
HtmlWeb htmlWeb = new HtmlWeb();
HtmlDocument doc = htmlWeb.Load(/* url */);
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[#href"])
{
// do stuff
}
You should have some info on how to identify the link. it may be id or name or the text. If the text is always same then check the inner text of that link.