/*
 * XMLtest.java
 *
 * Created on February 11, 2003, 10:28 PM
 */

package org.tienshiao.XMLLite;

import java.io.*;
/**
 *
 * @author  Tienshiao Ma
 */
public class XMLtest {
    
    /** Creates a new instance of XMLtest */
    public XMLtest() {
    }
    
    public static void testString(String s) throws java.io.IOException, XMLParserException {
        System.out.println("Input String ====>\n" + s);
        ByteArrayInputStream bin = 
            new ByteArrayInputStream(s.getBytes());
        XMLElement test = new XMLElement();
        test.parseFromReader(new InputStreamReader(bin));
        System.out.println("Output String =====>\n" + test.toString());        
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws java.io.IOException, XMLParserException {
        testString("<harder with=\"attribute\">\n" +
                   "<!--comment-->\n" +
                   "    <test>blah</test>\n" +
                   "    <empty></empty>\n" +
                   "    <otherempty/>\n" +
                   "</harder>");
        
        // SOAP example tests.  Stolen from http://www.w3.org/TR/SOAP/
        // Example 1
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                   "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <m:GetLastTradePrice xmlns:m=\"Some-URI\">\n" +
                   "           <symbol>DIS</symbol>\n" + 
                   "       </m:GetLastTradePrice>\n" + 
                   "   </SOAP-ENV:Body>\n" + 
                   "</SOAP-ENV:Envelope>\n");

        // Example 2 (fixed the /> in the starttag)
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                   "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <m:GetLastTradePriceResponse xmlns:m=\"Some-URI\">\n" +
                   "           <Price>34.5</Price>\n" +
                   "       </m:GetLastTradePriceResponse>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");
        
        // Example 5
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                   "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                   "   <SOAP-ENV:Header>\n" +
                   "       <t:Transaction\n" +
                   "           xmlns:t=\"some-URI\"\n" +
                   "           SOAP-ENV:mustUnderstand=\"1\">\n" +
                   "               5\n" +
                   "       </t:Transaction>\n" +
                   "   </SOAP-ENV:Header>\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <m:GetLastTradePrice xmlns:m=\"Some-URI\">\n" +
                   "           <symbol>DEF</symbol>\n" +
                   "       </m:GetLastTradePrice>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");
        
        // Example 6
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                   "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <m:GetLastTradePriceDetailed\n" +
                   "         xmlns:m=\"Some-URI\">\n" +
                   "           <Symbol>DEF</Symbol>\n" +
                   "           <Company>DEF Corp</Company>\n" +
                   "           <Price>34.1</Price>\n" +
                   "       </m:GetLastTradePriceDetailed>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");
        
        // Example 7
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                   "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                   "   <SOAP-ENV:Header>\n" +
                   "       <t:Transaction\n" +
                   "         xmlns:t=\"some-URI\"\n" +
                   "         xsi:type=\"xsd:int\" mustUnderstand=\"1\">\n" +
                   "           5\n" +
                   "       </t:Transaction>\n" +
                   "   </SOAP-ENV:Header>\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <m:GetLastTradePriceResponse\n" +
                   "         xmlns:m=\"Some-URI\">\n" +
                   "           <Price>34.5</Price>\n" +
                   "       </m:GetLastTradePriceResponse>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");
        
        // Example 8
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
                   "  SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <m:GetLastTradePriceResponse\n" +
                   "         xmlns:m=\"Some-URI\">\n" +
                   "           <PriceAndVolume>\n" +
                   "               <LastTradePrice>\n" +
                   "                   34.5\n" +
                   "               </LastTradePrice>\n" +
                   "               <DayVolume>\n" +
                   "                   10000\n" +
                   "               </DayVolume>\n" +
                   "           </PriceAndVolume>\n" +
                   "       </m:GetLastTradePriceResponse>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");

        // Example 9
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <SOAP-ENV:Fault>\n" +
                   "           <faultcode>SOAP-ENV:MustUnderstand</faultcode>\n" +
                   "           <faultstring>SOAP Must Understand Error</faultstring>\n" +
                   "       </SOAP-ENV:Fault>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");
        
        // Example 10
        testString("<SOAP-ENV:Envelope\n" +
                   "  xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
                   "   <SOAP-ENV:Body>\n" +
                   "       <SOAP-ENV:Fault>\n" +
                   "           <faultcode>SOAP-ENV:Server</faultcode>\n" +
                   "           <faultstring>Server Error</faultstring>\n" +
                   "           <detail>\n" +
                   "               <e:myfaultdetails xmlns:e=\"Some-URI\">\n" +
                   "                 <message>\n" +
                   "                   My application didn't work\n" +
                   "                 </message>\n" +
                   "                 <errorcode>\n" +
                   "                   1001\n" +
                   "                 </errorcode>\n" +
                   "               </e:myfaultdetails>\n" +
                   "           </detail>\n" +
                   "       </SOAP-ENV:Fault>\n" +
                   "   </SOAP-ENV:Body>\n" +
                   "</SOAP-ENV:Envelope>\n");
    }
}
