Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript



Java Examples

Quick Start
Java Unicode
Java Certs
Java Email
Java Encryption
Java FTP
HTML-to-XML
Java HTTP
Java IMAP
Java MHT
Java MIME
Java RSA
Java S/MIME
Java Signatures
Java Socket
Java Spider
Java Tar
Java Upload
Java XML
Java XMP
Java Zip

More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

 

Drop/Undrop Text Formatting Tags

This example demonstrates how text formatting tags are dropped by default. Calling UndropTextFormattingTags causes the tags to not be dropped. Text formatting tags are: b, font, i, u, br, center, em, strong, big, tt, s, small, strike, sub, and sup.

Download Java Programming Examples

// String-to-String HTML to XML conversion.
	
import com.chilkatsoft.CkHtmlToXml;
import com.chilkatsoft.CkByteData;
import com.chilkatsoft.CkString;

public class HtmlParse {
	
  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }
  
// Convert an HTML string into an XML string.  Demonstrate how text formatting
// tags can be optionally dropped.  Text formatting tags are: 
// b, font, i, u, br, center, em, strong, big, tt, s, small, strike, sub, and sup.

  public static void main(String argv[]) 
  {
    CkHtmlToXml htmlConv = new CkHtmlToXml();
    htmlConv.UnlockComponent("anything for 30-day trial");
    
	String html = "<html><body>This <b>is</b> a <i>test</i></body></html>";
	
	// To convert, set the HTML and get the XML:
	htmlConv.put_Html(html);
	String xml = htmlConv.xml();
	
	System.out.println(xml);
	
	/*
		The output is this:
		
		<?xml version="1.0" encoding="utf-8" ?>

		<root>
		    <html>
		        <body>
		            <text>This  is a  test</text>
		        </body>
		    </html>
		</root>
		
		*/
			
	// What happened to the <b> and <i> tags???
	// By default, text formatting tags are dropped.
	// If we call UndropTextFormattingTags, the tags will remain:
	htmlConv.UndropTextFormattingTags();
	
	xml = htmlConv.xml();
	
	System.out.println(xml);
	
	/*
		We now get this:
		
		<?xml version="1.0" encoding="utf-8" ?>

		<root>
		    <html>
		        <body>
		            <text>This </text>
		            <b>
		                <text>is</text>
		            </b>
		            <text>a </text>
		            <i>
		                <text>test</text>
		            </i>
		        </body>
		    </html>
		</root>
			
	*/
  }
}




 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.