Effectively, I want to take an XML string, utilize the power of Tag Helpers representing the XML tags, and have it render the XML.
I can make Tag Helpers easily enough to generate what I want, but I can't seem to find a way to render an XML string as Razor so the Tag Helpers will work.
Related
I want to extract data from a meta tag but the tag is as follows
<meta property="og:description" content="blah"/>
Since there is no id/class/etc. I can't use
driver.FindElement(By.[id/class/etc.]);
This meta tag has a unique property and content so I am wondering if there is any better way to locate and extract the content than selecting all "meta" tags and iterating through them.
While extracting data from a meta tag, I would suggest to use the attributes as much as possible. In your case :
XPath:
driver.FindElement(By.XPath("//meta[#property='og:description' and #content='blah']"));
CssSelector:
driver.FindElement(By.CssSelector("meta[property='og:description'][content='blah']"));
You can use xPath to grab the specified meta tag
driver.FindElement(By.XPath("//meta[#property='og:description']"));
You can use this xpaths
driver.FindElement(By.XPath("//meta[contains(#property,'og:description']"));
or
driver.FindElement(By.XPath("//meta[contains(#property,'og:description') and contains(#content,'blah')]"));
How would i show the output as HTML. I have tried HTML Decode and it still didn't work.
#section Grid {
#Server.HtmlDecode(lister.gen(new System.IO.StreamReader(Server.MapPath("~/Grid.xml")).ReadToEnd()))
}
Edit: I am taking XML from output.InnerXml (A XMLDocument) and trying to put it into a HTML Document as HTML (As in <a> is a link and <img> is a picture and not Text)
It turns out I had to add #Html.Raw along with HtmlDecode for it to display correctly
#Html.Raw(Server.HtmlDecode(lister.gen(new System.IO.StreamReader(Server.MapPath("~/Grid.xml")).ReadToEnd())))
If you want to show the HTML in an HTML page, you need to use HTML encode, not decode. This will put the proper tags in to turn < and > (and other HTML elements.
ADDED due to comment:
If showing XML AS HTML is the goal, then you will end up extracting the XML, from the DOM and putting it into the format you desire. You can bind XML to a table if you are simply trying to get it into a grid. If you need sorting, etc, LINQ to XML works nicely.
ADDED - second edit
Your XML appears to be XHTML, so you can simply throw it into the stream at the correct location. I would create a server control and then Response.Write the XML from the server control. You will want the decoded version based on what you posted. I was assuming you wanted to show the XML in the page, which was incorrect.
There is one minor bit of an issue with the XML, as it contains paragraph and div tags inside of an anchor tag. Not illegal, but not necessary in this case.
Well I am using DIFFPlex for comparing two html code fetching from db but i want to ignore html tags and their styling (only content), is there any way to achieve this.
I am waiting for your answer guys.
Thanks
I would suggest using the HtmlAgilityPack to strip all the html tags.
See the following question: https://stackoverflow.com/a/16875574/12919
I'm using the MVCSiteMapProvider here: https://github.com/maartenba/MvcSiteMapProvider and trying to style my breadcrumb navigation so it has a look similar to http://www.psd100.com/wp-content/uploads/2013/02/breadcrumb-navigation-psd-free-download022701.jpg)
Has anyone had success with this? Maybe by generating a ul & li based on the current page your'e on. Right now I'm getting the breadcrumbs but I want to add an arrow background image to them, and unless I can get a ul & li, it's not possible to do.
Thanks in advance!
Actually, there is no need to create your own HTML helper (although that is certainly an option). All of the HTML helpers in MvcSiteMapProvider are templated. You can customize the default templates by editing them in the /Views/Shared/DisplayTemplates/ folder.
For the sitemap path HTML helper, you would want to edit the SiteMapPathHelperModel.cshtml (or SiteMapPathHelper.aspx) file.
Note that you can also utilize template naming to use more than one template on the same HTML helper.
#Html.MvcSiteMap().SiteMapPath("MyTemplateName")
This would match a template named MyTemplateName.cshtml or MyTemplateName.aspx.
After scrubbing my field with AntiXss.HtmlEncode is there a way to remove all the html elements because they still show up as literals in the display?
No, there isn't. If you want to remove HTML elements and then HtmlEncode the result, you have to actually parse the code and remove the elements.
You can use the HTML Agility Pack or any other HTML parser to parse the content, get the InnerText of the root element (this will be only the text of the content) and then call AntiXss.HtmlEncode on that result.