Sorry ,im new in java. Currently i developing the tools to send the email, but the data such as (to, from, subject, message) i put it as xml file, where i can change it anytime. the question is how i need to send the data from xml to java variable ?
in c#: i can do like this, where i can link the variable. in java im not sure and have an error "eElement cannot be resolve".
String sto = (eElement.getElementsByTagName("to").item(0).getTextContent());
i want to link the data in this variable
String from = "test";
String to = "test";
String subject = "test";
String msg = "test";
sorry if this question look stupid or make you guys confuse.
thank you
What I have tried:
<pre> public static void main( String[] args )
{
System.out.println("Start Application");
ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Mail.xml");
MailMail mm = (MailMail) context.getBean("mailMail");
String from = "test";
String to = "test";
String subject = "test";
String msg = "test";
String sto = (eElement.getElementsByTagName("to").item(0).getTextContent());
mm.sendMail(from, to, subject, msg);
try {
File fXmlFile = new File("C:\\Users\\s012160\\Eclipse\\Spring-Myproject\\AA-Mail-Draft3\\SpringExample\\src\\main\\resources\\mailDetail.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
System.out.println("----------------------------");
NodeList nList = doc.getElementsByTagName("send");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
System.out.println("To : " + eElement.getElementsByTagName("to").item(0).getTextContent());
System.out.println("From : " + eElement.getElementsByTagName("from").item(0).getTextContent());
System.out.println("Subject : " + eElement.getElementsByTagName("subject").item(0).getTextContent());
System.out.println("Msg : " + eElement.getElementsByTagName("msg").item(0).getTextContent());
}
}
}catch(Exception e) {
e.printStackTrace();
}