Re: [Htmlparser-user] HTML parser for HTML translation
Brought to you by:
derrickoswald
From: Somik R. <so...@ya...> - 2003-01-30 17:44:46
|
You might be having an older version of the parser. Make sure you have the latest integration release 1.3-20030125 Regards, Somik --- Aminudin Khalid <ami...@mi...> wrote: > Hi, thank you for giving a sample program. > > I've tried to compiled the program but JAVAC > couldn't find HTMLVisitor > class . There are some other errors too. Below are > the codes and errors . > > > > *Errors : > StringTranslatingVisitor.java:1: cannot resolve > symbol > symbol : class visitors > location: package htmlparser > import org.htmlparser.visitors; > ^ > StringTranslatingVisitor.java:9: cannot resolve > symbol > symbol : class HTMLVisitor > location: class StringTranslatingVisitor > public class StringTranslatingVisitor extends > HTMLVisitor{ > ^ > StringTranslatingVisitor.java:39: cannot resolve > symbol > symbol : method visitAllNodesWith > (StringTranslatingVisitor) > location: class org.htmlparser.HTMLParser > parser.visitAllNodesWith(visitor); > ^ > StringTranslatingVisitor.java:40: cannot resolve > symbol > symbol : method getHTML () > location: class StringTranslatingVisitor > System.out.println(visitor.getHTML()); > * > > > > import org.htmlparser.HTMLParser; > import org.htmlparser.HTMLRemarkNode; > import org.htmlparser.HTMLStringNode; > import org.htmlparser.tags.HTMLEndTag; > import org.htmlparser.tags.HTMLTag; > > > public class StringTranslatingVisitor extends > HTMLVisitor{ > StringBuffer htmlData = new StringBuffer(); > > public void visitStringNode(HTMLStringNode > stringNode) { > String yourStuff="TextToBeTranslated"; > // Perform modifications here. > // finally, add to htmlData > htmlData.append(yourStuff); > } > > public void visitEndTag(HTMLEndTag endTag) { > htmlData.append(endTag.toHTML()); > } > > public void visitTag(HTMLTag tag) { > htmlData.append(tag.toHTML()); > } > > public String getHtml() { > return htmlData.toString(); > } > > public void visitRemarkNode(HTMLRemarkNode > remarkNode) { > htmlData.append(remarkNode.toHTML()); > } > > public static void main(String args[]){ > HTMLParser parser = new > HTMLParser("http://www.yahoo.com"); > parser.registerScanners(); > StringTranslatingVisitor visitor = new > StringTranslatingVisitor(); > parser.visitAllNodesWith(visitor); > System.out.println(visitor.getHTML()); > > > } > } > > > > Somik Raha wrote: > > >>What I want to do is to parse HTML code and > >>translate the content and > >>the put the translated text/content back into the > >>original HTML structure. > >> > >>Does this HTML parser suitable of doing this kind > of > >>task ? > >> > >> > > > >By translating content, I guess you mean > translation > >of meaningful text data (not tags). That is easily > >possible. You can look at the StringExtractor > example > >(org.htmlparser.parserapplications) or the > >StringFindingVisitor (org.htmlparser.visitors). > > > >The simplest approach is to write your own visitor > - > >StringTranslatingVisitor, that runs through the > entire > >html, and wherever it finds strings, these are > >translated as per your wishes. > > > >Here is a sample program : > >import org.htmlparser.HTMLRemarkNode; > >import org.htmlparser.HTMLStringNode; > >import org.htmlparser.tags.HTMLEndTag; > >import org.htmlparser.tags.HTMLTag; > > > >public class StringTranslatingVisitor extends > >HTMLVisitor { > > StringBuffer htmlData = new StringBuffer(); > > > > public void visitStringNode(HTMLStringNode > >stringNode) { > > String yourStuff=""; > > // Perform modifications here. > > // finally, add to htmlData > > htmlData.append(yourStuff); > > } > > > > public void visitEndTag(HTMLEndTag endTag) { > > htmlData.append(endTag.toHTML()); > > } > > > > public void visitTag(HTMLTag tag) { > > htmlData.append(tag.toHTML()); > > } > > > > public String getHtml() { > > return htmlData.toString(); > > } > > public void visitRemarkNode(HTMLRemarkNode > >remarkNode) { > > htmlData.append(remarkNode.toHTML()); > > } > > > >} > > > >To use this, create your parser - > >HTMLParser parser = new > >HTMLParser("http://someurl.com"); > >parser.registerScanners(); > >StringTranslatingVisitor visitor = > > new StringTranslatingVisitor(); > >parser.visitAllNodesWith(visitor); > >System.out.println(visitor.getHTML()); > > > >Regards, > >Somik > > > >__________________________________________________ > >Do you Yahoo!? > >Yahoo! Mail Plus - Powerful. Affordable. Sign up > now. > >http://mailplus.yahoo.com > > > > > >------------------------------------------------------- > >This SF.NET email is sponsored by: > >SourceForge Enterprise Edition + IBM + LinuxWorld = > Something 2 See! > >http://www.vasoftware.com > >_______________________________________________ > >Htmlparser-user mailing list > >Htm...@li... > >https://lists.sourceforge.net/lists/listinfo/htmlparser-user > > > > > > > > > > __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com |