Removing img tags from a bunch of tags, in a record field value, peoplecode.<img src = ".abc"> - peoplesoft

I have a field value in peoplesoft which contains a long description. The description has lot of HTML tags. from those I only want to remove the img tags (//). How can I do it through peoplecode?
And where to write the peoplecode.
Thanks in advance

It would help to have a little more information:
Is the string in the DB already, or coming from somewhere?
Do you want the rest of the HTML and just remove img field?
Is the HTML well-formed (valid html)?
Making assumptions here, but if the HTML is well formed, you can load it into an XMLDoc, and strip the img nodes.
&arrImgNodes = &inXMLDoc.GetElementsByTagName("img");
For each node in the the array, you can get the parent node and then remove the child.
xmlNode &pNode = &arrImgNodes[1].ParentNode;
&pNode.RemoveChild(&arrImgNodes[1]);
Then re-export your XML to a string:
&strHTML = &inXMLDoc.GenXmlString();
or
&strHTML = &inXMLDoc.GenFormattedXmlString();
If you're going to display the code to the user.

Related

Simple HTML Dom get href that begins with

I am using Simple HTML Dom to extract information from a remote source. I would like to get all href links that contain a particular piece of text (not all on a page). I have tried
->find('a[href*="/place"]')
and
->find('a[href="/place"*]')
and
->find('a[href="/place*"]')
but this returns empty results.
The href I am trying to get must begin with the text "/place".
Any suggestions?
Thanks
Match elements that have the specified attribute and it starts with a certain value, use [attribute^=value].
->find('a[href^="/place"]')
Ref: http://simplehtmldom.sourceforge.net/manual.htm#frag_find_attr
I do not now this app, however did you try using the asterisk like so ?
>find('a[href="/place*"]')

Can not display base64 encoded images in an HTML fragment in WinJS app

I'm writing a WinJS app that takes an HTML fragment the user has copied to the clipboard, replaces their
Later, when I go to display the .html, I create an iFrame element (using jQuery $(''), and attempt to source the .html into it, and get the following error
0x800c001c - JavaScript runtime error: Unable to add dynamic content. A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement. For more information, see http://go.microsoft.com/fwlink/?LinkID=247104.
I don't get the exception if I don't base64 encoded the images, i.e. leave them intact and can display iframes on the page with the page showing images.
If I take the html after subbing the urls for base64 and run it through toStaticHTML, it removes the src= attribute completely from the tags.
I know the .html with the encoded pngs is right b/c I can open it in Chrome and it displays fine.
My question is I'm trying to figure out why it strips the src= attributes from the tags and how to fix it, for instance, creating the iframe without using jquery and some MS voodoo, or a different technique to sanitize the HTML?
So, a solution I discovered (not 100% convinced it the best and am still looking for something a little less M$ specific) is the MS Webview
http://msdn.microsoft.com/en-us/library/windows/apps/bg182879.aspx#WebView
I use some code like below (where content is the html string with base64 encoded images)
var loadHtmlSuccess = function (content) {
var webview = document.createElement("x-ms-webview");
webview.navigateToString(content);
assetItem.append(webview);
}
I believe you want to use execUnsafeLocalFunction. For example:
var target = document.getElementById('targetDIV');
MSApp.execUnsafeLocalFunction(function () {
target.innerHTML = content}
);

Finding first Image from a content

How can I find an image from a content? I have a method in aspx I am calling this method for remove all html tags like this: Usage.DeleteHtml(Eval("content").ToString())
but I don't want delete img tag from content.. I should find the first image I will show it on my page.. like this:<img src="Usage.FindImage("content")" />
but couldn't write a method for finding image..
my DeleteHtml method:
public static string DeleteHtml(string text)
{
string mystr= Regex.Replace(text, #"<(.|\n)*?>", string.Empty);
return mystr;
}
I assume that your task is essentially retrieving the first image in document.
If your HTML document is a well-formed XML-document as well, you could easily solve your task using XPath.
More on XPath in .NET here.
XPath query to retrieve the first image's URL will look like this:
//img[1]/#src
Otherwise, if you really need to strip HTML, it's a duplicate to a couple of questions already:
Using C# regular expressions to remove HTML tags
How can I strip HTML tags from a string in ASP.NET?
How to clean HTML tags using C#
Short answer: use Html Agility Pack.

How to trim html tags from text in asp.net grid view?

I have used asp.net ajax html editor and i saved data in database. But now i want to retrieve it and show it in grid view. But when i retrieve that, it also shows those html tags (generated by asp.net ajax editor). So, i want to trim those tags and show plain text in grid view. How do i do that?
Thanks
Go to you db and look, how it is saved. Maybe it is save encoded. If it is not the case, you can use some simple regex to remove all those tags.
<[^<]+?>
This shows you just plain text and removes all Tags
To stripe the html tags from text you can utilize the
RegEx.Replace("str","Pattern","replacementstring "); method which there exist in
System.Text.RegularExpressions namespace
for example
Plain_Body = Regex.Replace(txtBody.Text, #"<[^>]*>", string.Empty);
here i am replacing the html specific characters with String.Empty or "" you can add additional characters if you wish to pattern like #"<[^>]*>" and spaces(&nbsp) and Ampersand(&amp) etc

Setting Page Title from an HtmlHelper class

I have an HTML Helper that essentially renders static content read from HTML files (inside of a vdir). There are cases when the HTML file has a title element defined and in such cases, the current page should use the given title. The content inside of the body should be rendered where the Helper class is referenced in the View.
This is how I call the helper.
<%=Html.StaticContent("staticcontent.htm",
new List<StaticContentTag>()
{
new StaticContentTag()
{TagKey=ReplaceTags.MarketName,
TagValue = "Austin"}
}, Model, true) %>
I'm passing in the ViewModel so that I can set the title and the last parameter is a flag that says whether to force the title or not.
The head has the title defined like this.
<title><%=Model.Title%></title>
I know what I'm doing wrong here by referencing the Model.Title element before even calling the helper. Any ideas on how I can work around this?
i believe ur title tag is rendered before u call the html helper in ur view. the purpose of helpers is to render html tags where they are called not to change contents of already rendered tags that can be done through javascript. however i would not use all that new keywords in my view. rather i would make a view model containing all required information for the view and then i would have no problem writing statement
<title><%=Model.title%></title>

Resources