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

63 Views Asked by At

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

1

There are 1 best solutions below

0
On

It would help to have a little more information:

  1. Is the string in the DB already, or coming from somewhere?
  2. Do you want the rest of the HTML and just remove img field?
  3. 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.