Sample API for XML simple example

Source: Internet
Author: User

Package testxml;
Import testemail .*;
Import java. Io .*;
Import org. dom4j. Io .*;
Import org. dom4j. Document;
Import org. dom4j. Io. outputformat;
Import org. dom4j. Io. saxreader;
Import org. dom4j. Io. xmlwriter;
Import org. xml. Sax. inputsource;
Public class prettyprint {
Public static void main (string [] ARGs ){
Try {
String body = "<A> <B> ASD </B> <C> asgf </C> </a> ";
// File = new file ("FILENAME ");
Bytearrayinputstream FIP = new bytearrayinputstream (body. getbytes ());
Inputsource is = new inputsource (FIP );
// Bytearrayinputstream FIP = new bytearrayinputstream (body. getbytes ());
// Fileoutputstream F = new fileoutputstream (FIP );
// F. Write (body. getbytes ());
Saxreader = new saxreader ();
Document Doc = saxreader. Read (is );
Outputformat format = outputformat. createprettyprint ();
Format. setencoding ("UTF-8 ");
String out;
Bytearrayoutputstream bout = new bytearrayoutputstream ();
Xmlwriter writer = new xmlwriter (bout, format );
Writer. Write (DOC );
Writer. Close ();
Byte [] B = bout. tobytearray ();
Stringbuilder sb = new stringbuilder ();
For (INT I = 0; I <B. length; I ++ ){
SB. append (char) B [I]);
}
Javamail163.endemail (sb. tostring ());
System. Out. println (sb. tostring ());
} Catch (exception ex ){
Ex. printstacktrace ();
System. Out. println ("Err ");
}

}

}

 

Package testemail;

Import java. util .*;
Import javax. Mail. Internet .*;
Import javax. Mail .*;
Public class javamail163 {
Static class mailauthenticator extends javax. Mail. authenticator {
String authenname;
String authenpass;
Public mailauthenticator (string authenname, string authenpass ){
Super ();
This. authenname = authenname;
This. authenpass = authenpass;
}

Public javax. Mail. passwordauthentication getpasswordauthentication (){
Return new javax. Mail. passwordauthentication (authenname, authenpass );
}
}

Public static void endemail (string context) throws addressexception,
Messagingexception {
Properties mailpro = new properties ();
// Mailauthenticator MA = new mailauthenticator ("peng_xu", "161523px ");
Mailpro. setproperty ("mail. SMTP. Host", "smtp.vanceinfo.com ");
// Mailpro. setproperty ("mail. SMTP. Auth", "true ");
Session session = session. getdefaultinstance (mailpro );
Session. setdebug (true );
Mimemessage MSG = new mimemessage (session );
MSG. setfrom (New internetaddress ("jessepengxu@163.com "));
MSG. setrecipient (message. recipienttype.,
New internetaddress ("jessepengxu@163.com "));
MSG. setsubject ("test sending email !!! ");
MSG. settext (context );
Transport. Send (MSG );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.