sample api for xml简单示例

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 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 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("[email protected]"));
msg.setRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]"));
msg.setSubject("测试发送邮件!!!");
msg.setText(context);
Transport.send(msg);
}
}

你可能感兴趣的:(C++,c,xml,C#,F#)