Archived Forum Post

Index of archived forum posts

Question:

Sample code to convert HTML to XML in Java

Nov 14 '14 at 11:49

Hi, I want a sampple code to convert my html file to XML using chilkat. The links provided in the documentation for Example#1, 2 & 3 are broken. I am trying the following code but its not giving me the results:

import com.chilkatsoft.CkHtmlToXml;
import com.chilkatsoft.CkByteData;
import com.chilkatsoft.CkString;

public class TestingCodes {
    static {
        try {
            System.loadLibrary("chilkat");
         } catch (UnsatisfiedLinkError e) {
             System.err.println("Native code library failed to load.\n" + e);
             System.exit(1);
         }
    }
    public static void main(String[] args) {
        System.out.println("Starting conversion");
        CkHtmlToXml obj = new CkHtmlToXml();
        obj.UnlockComponent("anything for 30-day trial");

        try{
        boolean b = obj.ConvertFile("C:\\Users\\user\\Desktop\\index.html", "C:\\Users\\user\\Desktop\text_op.xml");
        if(b)
            System.out.println("Converted successfully!");
        else
            System.out.println("Error in converting");
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

}

The output is: " error in converting" I am working with jdk 7 and I've installed the JDK 7 version for chilkat 64 bit, ran the runTest.bat, which in turn logged the version as 9.5.0.45 on cmd. Is there anything I am missing in the procedure to make it working?


Answer

The examples have been restored on the website.

To get information about the problem, examine the contents of the obj.LastErrorText after calling obj.ConvertFile.