Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Java
<pre> public static void main( String[] args )
    {
  	    	
//*************************start mail main ***********************************88
    	 	
    	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);
    
        //********************fetch data**********************
        
        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"); //get the element specific ID

        	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();
        }
Posted
Updated 29-Oct-17 22:44pm
Comments
Richard MacCutchan 30-Oct-17 4:52am    
I have deleted your duplicate of this question; please do not repost.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900