Custom HTML tags in JTextPane

Hi all,
I have seen this topic broached before but, in spite of many hours searching, haven't found the answer I'm looking for...
I jave a JTextPane containing an HTMLDocument and want to render elements within my own custom tag 'Custom' outlined in red.
I have subclassed HTMLEditorKit as follows:import javax.swing.text.ViewFactory;
import javax.swing.text.html.HTMLEditorKit;
public class HTMLEditorKitForCustom extends HTMLEditorKit{
     public ViewFactory getViewFactory(){
          return htmlFactoryForCustom;
    private static final ViewFactory htmlFactoryForCustom = new HTMLFactoryForCustom();
}I have subclassed HTMLEditorKit.HTMLFactory as follows:import javax.swing.text.View;
import javax.swing.text.Element;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.StyleConstants;
public class HTMLFactoryForCustom extends HTMLEditorKit.HTMLFactory{
     public View create(Element element){
          Object object = element.getAttributes().getAttribute(StyleConstants.NameAttribute);
          if(CustomView.CUSTOM_KEY_TAG.equals(object)){
               return new CustomView(element);
          return super.create(element);
}And, I have subclassed LabelView as follows:public class CustomView extends LabelView{
     public CustomView(Element element){
          super(element);
     public void paint(Graphics g, Shape a){
          super.paint(g, a);
          Rectangle rectangle = a instanceof Rectangle ? (Rectangle)a : a.getBounds();
          Graphics2D g2d = (Graphics2D)g;
          g.setColor(Color.RED);
          g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
     public static final String CUSTOM_KEY_TAG = "Custom";
     public static final String CUSTOM_TYPE_TAG = "ccVarType";
     public static final String CUSTOM_NUMERIC_TYPE_TAG_VALUE = "Numeric";
}The JTextPane in question has its EditorKit set to my HTMLEditorKitForCustom throughtextPane.setEditorKit(new HTMLEditorKitForCustom();In combination, these classes ensure that when a <Custom>...</Custom> set of tags is encountered, the text between is rendered with a red outline.
This works fine when the custom tags and text are inserted but, as soon as a change is made that affects the paragraph containing the custom tags (for example, change alignment, font size, etc.), the content disappears. However, the underlying HTML still shows the <Custom> tag, but with no closing tag and without the text the tags once contained.
E.g. <Custom>Fred</Custom> becomes simply <Custom>.
Any help in solving this problem will be greatly appreciated!
Chris.

Stas, thanks for your response!
I did try registering the tag, and associating it with a SpecialAction then with a CharacterAction (I want the user to be able to change the font style, etc. of these Custom items).
I did this by creating HTMLDocumentForCustom (original name, huh!), subclassing HTMLDocument and inner HTMLReaderForCustom:// (Within HTMLDocumentForCustom)
public class HTMLReaderForCustom extends HTMLReader{
  public HTMLReaderForCustom(int pos){
    super(pos, 0, 0, null);
    registerTag(new HTML.UnknownTag(CustomView.CUSTOM_KEY_TAG), new SpecialAction());
}Then I created a new HTMLDocumentForCustom and did textPane.setDocument(document). Now, when I inserted the text between Custom tags, I got this exception:javax.swing.text.BadLocationException: Invalid insert;
     at javax.swing.text.GapContent.insertString(GapContent.java:109);
     at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:722);I was using the following code to insert the text:SimpleAttributeSet attributes = new SimpleAttributeSet();
attributes.addAttribute(StyleConstants.NameAttribute, CustomView.CUSTOM_KEY_TAG);
try{
  document.insertString(1, "Custom Here!", attributes);
catch(BadLocationException ble){
  ble.printStackTrace();
}Inserting at position 1 was working fine before trying to subclass HTMLDocument and HTMLReader, and there's already text in the document before trying the insert -- in fact it didn't matter what the insert location was set to, the exception kept occurring.
Can you see anything obvious I've missed or am I barking totally up the wrong tree?
Chris.

Similar Messages

  • Custom html tags with JEditorPane

    I'm trying, to use my own tags within html in the JEditorPane. An insert parses without exception but the html in the pane is missing the custom tags that I attempted to insert. I have tried to use the 'setPreservesUnknownTags' command on the html document, but it appears to have no affect. This is the code I have been trying to use:
    edtHTML.insertHTML(docHTML, 0, "<p><my:link id=\"12\">ABC</my:link></p>", 0, 0, HTML.Tag.P);
    I have also tried
    edtHTML.insertHTML(docHTML, 0, "<my:link id=\"12\">ABC</my:link>", 0, 0, new HTML.UnknownTag("my:link"));
    Can anyone help?
    Thanks

    I have no example for custom Tags but I found out that every tag is stored as an attribute.
    You can access the attributes if you use a JTextPane. There is a method (i don't know the name yet I will find out tomorrow in the office) which gives you the AttributeSet of each Character at the Carent position. All characters have an attribute "name" and the value of this attribute should be the name of the tag you've inserted.
    The only problem is that I had to read out every character so it's quit slow.
    If you could find a better solution please let me know ([email protected]).
    Thank you.
    J&ouml;rn

  • How to insert row in usercreat table(useing HTML tags)in jtextPane

    hi all
    i creat userdefined table in JTextPane like this
    tableBody.toString() -- iam passeing table tags
    htmlKit.insertHTML(htmlDoc, caretPos, tableBody.toString(), 0, 0, HTML.Tag.TABLE);
    i want to insert a row in table.. i did like this
    htmlKit.insertHTML(htmlDoc, caretPos, sRow.toString(), 0, 0, HTML.Tag.TR); it working..
    but it inserting in current location.. i want to insert ending of table...
    pls help me

    Hi,
    Follow the below logic,
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0001.
      MODULE POPULATE_TABLE_CONTROL. --> Get the data from table store in 
                                                                          ITAB
      LOOP AT GT_CTRL_LP_D516 INTO GS_WA_CTRL_LP_D516
           WITH CONTROL CTRL_LP_D516
           CURSOR CTRL_LP_D516-CURRENT_LINE.
      The following module moves data to control
        MODULE MOVE_TO_CONTROL.--> Move data from ITAB to table control
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP AT GT_CTRL_LP_D516.
      ENDLOOP.
      MODULE EXIT AT EXIT-COMMAND.
      MODULE USER_COMMAND_0001.  --> Here you have to take out the values from table control and update database table
    Reward points if helpful.
    Thanks and regards,
    Mallareddy Rayapureddy,
    Munich, Germany.

  • Inserting custom HTML tags into a HTMLDocument to be displayed in a JEditor

    Does anyone know how to insert custom tags into a HTMLDocument to be displayed in a JEditorPane?
    I have tried using the following code,
    kit.insertHTML( doc,
                    jep.getCaretPosition(),
                    "<testtag>FFFF</testtag>",
                    0,
                    0,
                    new HTML.UnknownTag("testtag") );When the above code is run the handleStartTag, handleEndTag and handleText methods are called on the HTMLReader but nothing is inserted into the document model? Can anyone help?
    I have created an instance of HTML.UnknownTag,
      public static HTML.Tag testTag = new HTML.UnknownTag("testtag");I have subclassed HTMLEditorKit and overridden the getParser() method,
      protected Parser getParser(){
        DTD dtd = null;
        try {
          dtd = createDTD( DTD.getDTD("html32"), "html32" );
        } catch ( Exception e ) {
          e.printStackTrace();
        dtd.getElement( "testtag" );
        Parser p = new ParserAdaptor( new DocumentParser( dtd ) );
        return p;
      }I have subclassed HTMLDocument and HTMLDocument.HTMLReader and created a TagAction for my new tag.
    The following code works fine, the custom tag is in the document model,
        String contents =    "<html>"
                           + "<body>"
                           + "<testtag>Here is some text</testtag>"
                           + "</body>"
                           + "</html>";
        ((HTMLDocument)jep.getDocument()).setPreservesUnknownTags(true);
        jep.setText( contents );

    I've been trying to get <blockquote> insert working in an editor but it seems to be a quite difficult task even if it's only about inserting a couple of tags into the right slot! This is the closest I got:
    HTMLDocument doc = (HTMLDocument)editor.getDocument();
    int start = editor.getCaretPosition()
    int paraStart = doc.getParagraphElement(start).getStartOffset();
    int paraEnd = doc.getParagraphElement(start).getEndOffset();
    String insideBlockQuotes = doc.getText(paraStart, paraEnd - paraStart);
    doc.setOuterHTML(doc.getParagraphElement(start),"<blockquote><p>"+insideBlockQuotes+"</p></blockquote>");
    This is how it works: Get the current paragraphs start and end positions, read the text between the start and end into a string, replace the paragrapElement with <blockquote><p>..the text from string..</p></blockquote>.
    This works 'in about' but it's far from perfect.. it has the following problems:
    1. It looses all formatting from the quoted paragraph (bold etc. tags from the quoted part)
    2. It assumes that the paragraphElement was a <p> (could have been another element too!)
    3. It's ugly
    Anybody come up with a better way to use blockquote?

  • Extract text file with HTML tags from JTextPane

    hello world
    I have a big problem !
    I am creating an applet with a JTextPane ...
    so I can write text, (bold, italic etc), i can insert images.
    Now i want to create a text file with all the HTML tags
    corresponding to what I wrote in my JTextPane.
    I want to have and save the HTML file corresponding to what i wrote ...
    Is it possible ? Help me please ....
    Jeremie

    writing to a file from an applet is going to take a fair amount of work on your part.
    in order to write to a file from your applet, you have to use servlets or jsp to write to a file on your server. if you wish to write locally, look into signing your applet or policy settings of your browser.
    for writing to a file to the server, i suggest you look into servlets and tomcat to run the servlets.
    i just finished a project that used servlets and they take some time to figure out, but its definitely worth your time.
    here are some websites...
    http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html
    http://jakarta.apache.org
    other websites have tutorials that you can look at too
    Andy

  • Nested html-tags in JTextPane not possible?

    Hi.
    Why does JTextPane not support contents like this:
    <p align="center">
      <h2>Hello, world!</h2> <!-- nested tag -->
    </p>This code is parsed and changed into:
    <p align="center">
    </p>
    <h2>Hello, world!</h2>Is there any possibility to get around this?
    Cheers,
    kelysar

    I do not know about how to treat HTML by JTextPane.
    According to http://www.w3.org/TR/html4/sgml/dtd.html,
    <!ENTITY % block
    "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
    BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">
    So you cannot use h2 element in p element.
    Regards,

  • Custom Views: Set style of text in custom HTML tags

    hi all, I'm using an extended JEditorPane to render HTML containing custom tags e.g. <mytag>Text</mytag>
    My ViewFactory dynamically loads a class based on the name of the tag to return the View for that tag. (The idea being you can add any tag, by just providing a View class to render it). It's working to the extent that I can use the View.paint() method to paint a square of text before and after the content element.
    What I need to do is set the style (attributes) of the text contained in the custom tags. Is this possible?
    A call to doc.setCharacterAttributes(startoffset, endoffset, attrs, true); from the View results in a "Attempt to mutate in notification", possibly because the HTMLDocument is locked at this time.
    Any help/advice would be greatly appreciated.
    Thanks.

    I'll rephrase. Is it possible to change the HTMLDocument from a View object. Forgive my lack of understanding.

  • How to insert customized HTML tags?

    Hi
    I insert a lot of tags like <p class="foo"> or say <span onmouseover=”doAction(this);”>.
    Is it possible in Dreamweaver CS5 to extend a list of insertable tags with my customized tags and do steps like
    select some text (say “some text”),
    them choose a tag from the list (say <span onmouseover=”doAction(this);”>.)
    A fragment “<span onmouseover=”doAction(this);”> some text</span>” will be inserted into the file instead of  selected “some text”.
    Thank you in advance.

    Have you used the Snippets folder to store reusable code fragments?
    I use my snippets folder often. Go to an insertion point in your document and double click on the Snippet.
    http://webdesign.about.com/cs/dreamweaver/ht/htdwusesnip.htm
    Another option is to create and use commands from History steps:
    http://help.adobe.com/en_US/dreamweaver/cs/using/WSc78c5058ca073340dcda9110b1f693f21-7780a .html
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Custom HTML meta tags in head section

    We want to add custom HTML code to our html-type (HTMLHelp,
    FlashHelp, WebHelp) output.
    We know how to add HTML code to the <body> section, by
    selecting from RoboHelp's main top menu "Insert > HTML".
    We also know how to add HTML code to multiple topics at once,
    by adding the HTML code to the header and/or footer or a template,
    and linking the relevant topics to that template.
    We now want to add HTML code (in particular, custom META
    tags) to the <head> section. However, it appears that the
    content of the template header appears in the <body> section.
    Of course, we could run a search-and-replace-all on our
    existing topics, to replace existing HTML code on the <head>
    section with our custom code. But we would need to remember to do
    this each time we add a new topic. It is not a big deal, but this
    does not seem to be a very efficient way of doing this.
    We figure that there must be some type of collection of
    HTML-templates that RoboHelp uses each time a new topic is created,
    to automatically insert some standard HTML code. But, do we have
    easy access to such HTML-templates? Where are they stored?
    Thanks for you help!

    Have you tried working in the "True Code" editor? This seems
    to be all you need to do.
    John

  • Can a DTD map custom styles to standard HTML tags?

    Hi,
    Every week the publishing house I work for has to manually copy the entire content of a weekly magazine on an article-by-article basis into an online database, the web version of the magazine. This means copying the styled InDesign content and inserting it into the database as plain text, re-finding all those italics (and any other styling) and putting it all back manually.
    I already know that I can create tags with all the basic HTML styles needed in the 'Tags' palette in InDesign, and then export that.
    The trouble is that when I re-import the XML file, I have to laboriously map the custom house-styles (there are many of them and they're boiler-plate, i.e. consistent, across all the magazine's InDesign styles) to the imported HTML styles.
    So here's my question:
    Am I wrong to believe that it's possible to create a DTD that would import not only the HTML tags but their relationship to the existing, custom-named InDesign tags that are common to all the magazine's documents?
    As an InDesign wish-feature, what's missing from the 'Tags' corner-menu is 'Export DTD' - if that was available, I could map the whole relationship between Indesign Styles/HTML styles just one time and later import the DTD on other articles; which would tell the Structure View how to convert our custom house-styles (both Paragraph Styles and Character Styles) into HTML tags and cut this time-consuming task in half.
    Thanks!
    EDIT: I perhaps should have mentioned that obviously the final stage after this 'dream conversion' is to export the XML from the Structure View. Then I can just open the saved XML file and paste it into the CMS with formatting intact.
    Added extra explanation of the workflow.

    geekbelief wrote:
    Googling XSLT and InDesign, it seems that such a stylesheet, if I were to create it, possibly couldn't handle spaces in the original InDesign style-names..? If anyone knows that for a fact, I'd be glad to be aware of it before starting down a long path to a roadblock.
    That's a good question. Let's find out together, shall we. I just created a text frame with Lorem Ipsum text, and created "a style" (with space) and "bstyle" (without). Now ... Map Style to Tag doesn't work, presumably because the tags don't exist and I assumed this would *create* them. And if you create one, ID complains "tags cannot contain tabs or spaces". (So can you have a Tab in your paragraph style name then? Gosh.)
    ... Forcing in a Non-breaking Space (#160) also doesn't work, this time ID simply says "A tag name cannot contain the character ' '."
    I think that's one you have to do manually.
    geekbelief wrote:
    I'm guessing that if I wanted to change the InDesign style 'Subheader' into 'h2', that snippet of the XSLT would be like this...?
    <xsl:template match="Subheader"><h2><xsl:apply-templates /></h2></xsl:template>
    Yeah, that's the correct syntax. But you cannot use an XSLT for mapping InDesign styles to tags. The process as I described works when importing your XML into InDesign, and changes the tags in the XML file to match InDesign styles. That's the other way around.
    I don't expect anyone to write this for me, but any hints or links to tutes that I haven't yet found would be appreciated!
    For a simple one-to-one translation of tag names, you can use this all the way. You only need any other XSL command if you want to do more than simple translation, such as filtering, moving, combining, or separating tags or their contents.
    There are lots of good tutes on the 'web for XSLT, although it seems interest has diminished lately. Half a decade ago XSLT was "hot"; nowadays the iPad is. Is there any news on improvements for ID's native XSLT support in CS6? I dare bet there are none at all -- it's already been deemed "yesterday's technology" by Adobe's Dev Team, just as Flash was discarded per CS5.5. I'm sure next year DPS will follow; and the year after that EPubs will be gone for good as well, replaced by holograms, transmitted live from your local library.

  • HTML Tags escape while exporting to PDF

    Hi friends,
    I have two columns in my BI report like
    Business Group(BG) and OU
    Since in the BG column under the edit formula i used the html tags to show each and every BG column value in bold like below
    '<b>' || "D1.Company"."Business Group Full Name" || '</b>'
    Now the report is appearing fine in answers and dashboard but when i export the same report to PDF i can see the html tags in each and every name of the BG group.
    Is there anything to be done to escape these html tags in PDF while exporting.
    And also if we give the tooltip for the numeric columns like below under the column properties-->Data format-->Custom like
    [html]<p title=\""Employee Count" \">#
    And after that if i tried to escape the same report with the tooltip on the numeric column to pdf means, the number values are missing for the entire column in the PDF, but this case is not appearing while exporting the report to pdf if i set the tooltip to the text column, as the values is missing only for the tooltip of the numeric column. What could be the fix for this problem.
    Thanks
    Regards,
    Saro

    Hi svee,
    Thanks for the reply.
    For an example i tried with the bold option in the edit formula inorder to portray the html tags problem while exporting it to the pdf inspite of using the default bold option within the column properites like u said.
    Suppose if i used html tags like
    <br>, </br>
    in the edit formula section or if i used any other html tags which is not present as a default option in bi like bold. At that time while exporting the report to pdf i can face the issue.
    And also i need ur suggestion regarding with the values disappearing for the numeric column if a tooltip is used in it while exporting it to the pdf.
    Regards,
    Saro

  • How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail

    I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
    I have everything working except for embedding images.
    Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
    Here's a bit of code to set the context.
    JTextPane bodyPane = new JTextPane();
    bodyPane.setEditorKit(htmlEditorKit);
    bodyPane.setTransferHandler(new DropHandler());
    bodyPane.setDocument(new HTMLDocument());
    In the DropHandler I have the following:
    HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
    HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
    int caretPos = bodyPane.getCaretPosition();
    At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
    String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
    htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
    This works just fine. The image is displayed in the document at the point of insertion.
    However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
    What is the best way to do this?
    There is a technique for embedding the actual image in the html, using this syntax:
    String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
    I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
    From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
    Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
    I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
    I have yet to see an example that shows the complete package.
    Am I right that the data option I mentioned is not going to work?
    Am I right that cid is the best approach, and do I understand how to use it?
    Is there something else?
    Thanks
    John

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • WebElements, Custom HTML and missing !DOCTYPE

    In our Crystal Reports, we are using a combination of the WebElements library along with a custom HTML function library to display advanced HTML elements for parameter selection. Our custom HTML library contains some JQUERY UI components. We are using IE7.  Our BO environment is R3 SP4.
    The issue that I have encountered is that the JQUERY UI components require a valid <!DOCTYPE> specification to render correctly -  such as  <!DOCTYPE HTML> or <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> but from my research, the Crystal Report Viewer appears to not be adding a valid <!DOCTYPE> specification to its HTML stream (which most modern HTML always includes).
    Without the presence of a valid <!DOCTYPE>  specification, IE7 is rendering the HTML in a "BackCompat"  mode instead of a "CSS1Compat" mode.
    Any help in overcoming this issue - or getting SAP to add <!DOCTYPE> to the Crystal Report viewer - would be greatly
    appreciated!

    Hello Jamie,
    thank you alot for your suggestions. In detail i am facing the same problem described in this thread:
    Setting the HTML DOCTYPE with WAD?
    This thread and also my problem deals with DOCTYPE problems within BW 3.5 Web Application Designer using standard web templates. The websites are generated/rendered by a class called CL_RSR_WWW_ITEM_TEMPLATE which inserts javascript before the DOCTYPE tag.
    One solution would be to change the standard class by:
    1. Creating a new class inheriting from  CL_RSR_WWW_ITEM_TEMPLATE
    2. Overload the method RENDER, copy all code and concatenate at the end of the method the DOCTYPE element to the member n_sx_output-string
    3. Adjust the setting of the default template within the table RSRRENDERERATR for the key REN_NAME=CL_RSR_WWW_ITEM_TEMPLATE, ATTR_NAME=NAME. Change the field VALUE from "CL_RSR_WWW_ITEM_TEMPLATE" to the new class.
    This solution should work, but is kind of crappy and the risk for side effects on other renderings is too high.
    I was not able to find the note mentioned in the posting of Joel Blackthorne. What does "customer note" mean?
    I will also post this message within the other thread, because it is a little off topic here, i guess. Sorry for that.
    Thanks again, Jamie,
    Regards Felix

  • HTML tags showing up in the pages also in 2.0?

    Hi,
    After a 5 minutes test of our application after an upgrade to 2.0 I found 3 places where html tags is showing in the bottom of the page. Normally it’s a html tag that is not getting closed. The examples look like this:
    &#60;/
    &#60;INPUT TYPE="hidden" NAME="p_min_row" VALUE
    &#60;script language="JavaScript1.1" type="text/javascript"
    We have been telling the customer that these problems would disappear with the new version, but it have not. I know that we were not the only ones with these problems on 1.6. How are you dealing with this? I can not imagine what our customer is going to say when we tell them that we can’t use htmldb for the project, especially since we were the ones pushing htmldb.
    In release 1.6 the problems were normally only in Internet Explorer and not in Mozilla. I have not been able to check on 2.0, because since the upgrade it is only possible to logon using Internet Explorer. Mozilla gives a script error. :-)

    Hello,
    I have a feeling all your problems are related take a look at this thread. I found it in 10 seconds of searching the forum.
    strange tags
    It's always best to do a quick search first most likely you are not the first person to have this problem.
    Carl

  • How to remove html tags from a column

    Hi
    Problem is this: I get a column with a comma separated list of id's and I can successfully parse these id's and use them elsewhere. BUT, occasionally there are html tags within that id list like this:
    1082471,1237423<br xmlns="http://www.w3.org/1999/xhtml" />
    Is there a way to just automatically remove all tags from a column? Could do this with regex, but since there is no support, I don't know what to do.

    Hi,
    If the HTML can be detected by a starting symbol like „<“, then you could use the following:
    Unfortuntely the operation “ReplaceRange” is only available on a Text-level, so you have to invoke a function (at least to my knowledge). You also need an Index-column in your table, so if you don’t have it, you need to create one as well.
    This is your function:
    let
       fnRemoveHTML = (Value, Index) =>
    let
       Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
       IndeNo = Index,
       Value_ = Source{IndeNo-1}[Value],
       length = Text.Length(Text.From(Value_)),
       position = Text.PositionOf(Text.From(Value_), "<"),
       range = length-position,
       new= if Value_ is number then Value_ else Text.ReplaceRange(Value_, position, range, "")
    in
        new
    in
      fnRemoveHTML
    And this is how you invoke it:
    let
        Quelle = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
        Last = Table.AddColumn(Quelle, "Custom", each fn_RemoveHTML([Value], [Index])),
        ChangedType = Table.TransformColumnTypes(Last,{{"Custom", type number}})
    in
        ChangedType
    Provided your table is called “Tabelle1” & the column with your values to be replaced “Value” & your index-col “Index”
    Imke

Maybe you are looking for