Liquid XML Data Binder 2020
Liquid XML Data Binder (C++, Java, VB6) / Help With Your Evaluation / Bookstore Sample / SampleApp.java
In This Topic
    SampleApp.java
    In This Topic
    package SampleApp;
    
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class SampleApp
    {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            public static void main(String[] args)
            {
                            writeTest();
                            readTest();
            }
            
            public static void writeTest()
            {
                    try
                    {
                            // to create the XML document from scratch
                            BookStoreLib.Bookstore bs = new BookStoreLib.Bookstore();
                            BookStoreLib.BookType book = bs.getBook().add();
                            book.setTitle("The Autobiography of Benjamin Franklin");
                            book.setPrice(8.99);
                            book.setPublicationdate(new com.liquid_technologies.ltxmllib18.DateTime((short)1981, (byte)5, (byte)11));
                            book.setISBN("1-861003-11-0");
                            book.getAuthor().setFirst_name("Benjamin");
                            book.getAuthor().setLast_name("Franklin");
                            book.setGenre("autobiography");
                            String strXml = book.toXml();
                            System.out.println("This is the XML\n" + strXml);
                    }
                    catch (Exception e)
                    {
                            // Note : exceptions are likely to contain inner exceptions
                            // that provide further detail about the error.
                            Throwable te = e;
                            while (te != null)
                            {
                                    System.out.println("Error - " + te.getMessage());
                                    te = te.getCause();
                            }
                    }
            }
    
            public static void readTest()
            {
                    try
                    {
                            // to create the XML document from scratch
                            BookStoreLib.Bookstore bs = new BookStoreLib.Bookstore();
                            bs.fromXmlFile("BookStoreSample.xml");
    
                            for (int i=0; i<bs.getBook().size(); i++)
                            {
                                    BookStoreLib.BookType book = bs.getBook().get(i);
    
                                    System.out.println("Book Title           " + book.getTitle());
                                    System.out.println("    Price            " + book.getPrice());
                                    System.out.println("    Author           " + book.getAuthor().getFirst_name() + " " + book.getAuthor().getLast_name());
                                    if (book.isValidPublicationdate())
                                            System.out.println("    Publicationdate  " + book.getPublicationdate().toString());
                                    else                    
                                            System.out.println("    Publicationdate  Not Listed");
                                    if (book.isValidISBN())
                                            System.out.println("    ISBN             " + book.getISBN());
                                    else                    
                                            System.out.println("    ISBN             Not Listed");
                                    if (book.isValidGenre())
                                            System.out.println("    Genre            " + book.getGenre());
                                    else                    
                                            System.out.println("    Genre            Not Listed");
                            }
                    }
                    catch (Exception e)
                    {
                            // Note : exceptions are likely to contain inner exceptions
                            // that provide further detail about the error.
                            Throwable te = e;
                            while (te != null)
                            {
                                    System.out.println("Error - " + te.getMessage());
                                    te = te.getCause();
                            }
                    }
            }
    }