Menu

ParserUtils.trimTags

Help
wbrian
2007-12-10
2013-04-27
  • wbrian

    wbrian - 2007-12-10

    Hi,
    thank you for all your previous assistance.

    I'd like to remove the st1: tags inserted by the "save as html" option in MSWord (for ex.
    <st1:place>.
    I've created my own tags for these that extend CompositeTag; and a PrototypicalNodeFactory:

        PrototypicalNodeFactory pnf = new PrototypicalNodeFactory ();
        pnf.put("B", new BoldTag());
          ....
        pnf.put("ST1:CITY", new ST1CityTag());
        pnf.registerTags();   

    This part seems to be working coz I can find their correct parents; ie they are indeed composite tags.

    The following strips out all the span tags but leaves their contents intact:
        PrototypicalNodeFactory nodeFactory = TagFactory.getFactory();
        Parser parserTwo = new Parser();
        parserTwo.setNodeFactory (nodeFactory);
        parserTwo.setResource(ParserUtils.trimTags(q, Span.class, true, false));
            nodes = parserTwo == null ? null : parserTwo.parse(null);

    q is a html string of the complete contents of an html file.

    but when I replace Span.class with one of my ST1 tags nothing happens;
    nor when I substitute  BoldTag.class.

    and now I'm stuck.
    any assitance that you might be able to provide would be greatly appreciated.
    Brian

     
    • Derrick Oswald

      Derrick Oswald - 2007-12-10

      Just checking... Are you using your modified PrototypicalNodeFactory - pnf - or a fresh one created as:
        PrototypicalNodeFactory nodeFactory = TagFactory.getFactory ();
        Parser parserTwo = new Parser ();
        parserTwo.setNodeFactory (nodeFactory);

       
    • wbrian

      wbrian - 2007-12-11

      Hi Derrick,

      TagFactory.getFactory () has the following code:

      public static PrototypicalNodeFactory getFactory(){

         PrototypicalNodeFactory pnf = new PrototypicalNodeFactory ();
         pnf.put("B", new BoldTag());
         ....
         pnf.put("ST1:CITY", new ST1CityTag());
         pnf.registerTags();
         return pnf;
      }

      so, pnf is returned and nodeFactory is assigned pnf and so both are pointing at the same
      PrototypicalNodeFactory.

      the code above works on Span; ie all Span tags are removed but not their content.
      the PrototypicalNodeFactory seems to be working, otherwise, coz a visitor run against an html test file can correctly output the parent  for each of the new tags in the factory.

      are there other tests of composite tags that might fail & would indicate where the problem lies?  in other words, is there a property of composite tags that I may not have yet set?

      thank you again for your assistance,
      Brian

       
      • Derrick Oswald

        Derrick Oswald - 2007-12-11

        I'm sorry I don't know.
        You'll probably need to debug into trimTags to see what's going on.
        I didn't write it, and it hurts my brain to try and figure it out.
        Make sure your tag name is upper-case in the ST1:CITY class.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.