Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change centent of xml file under eclipse

Status
Not open for further replies.

newprog39

Programmer
Sep 26, 2015
15
DZ
Hi all:

I have just started working on eclipse java in last few weeks in order to create an xml file :

Acutually i have to create three type of xml file not at once each one must have a buttons separatly :

type1 xml file is listed in attachemnt .

I want to do the following :

create three button for each xml type and 13 edittext to enter value in order to update the xml file .

for example :

SET cal : ( 3 edittext)
emaxt : ( 9 edittext)
uname : ( 1 edittext) in exmaple in attachemnt i have added ZLN20 and the other part is fixed :

firt line : X_10"/
second line : X_20"/
third line : X_30"/

I have started with this :



Code:
package xml modify;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
 
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
 

public class xmlupdate {

	public static void main(String[] args) {
		DocumentBuilderFactory icFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder icBuilder;
        try {
            icBuilder = icFactory.newDocumentBuilder();
            Document doc = icBuilder.newDocument();
        Element mainRootElement = doc.createElementNS("!DOCTYPE MODIFYLMN SYSTEM","MODIFYLMN.dtd");
            doc.appendChild(mainRootElement);

thanks for your help
 
 http://files.engineering.com/getfile.aspx?folder=e77bb117-ed37-4c89-8e08-c693b1a655af&file=xml_type1.txt
Hi:

I want to change some data inside xml file listed in attachemnent as template via JtextField .

SET cal : ( 3 JtextField)
emaxt : ( 9 JtextField)
uname : ( 1 JtextField) in exmaple in attachemnt i have added ZLN20 and the other part is fixed :

firt line : X_10"/
second line : X_20"/
third line : X_30"/

The XML Model created by JDOM or SAX didn't give me what I want for example the first line can't be generated :

<?xml version="1.0" encoding="ISO-8859-1"?>

I have started with this but I can't carry on , is there any other idea ?

Code:
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Panel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
 
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class data {

	private JFrame frame;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_9;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					data window = new data();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public data() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 380, 269);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JButton btnRun = new JButton("Run xml1");
		btnRun.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				DocumentBuilderFactory icFactory = DocumentBuilderFactory.newInstance();
		        DocumentBuilder icBuilder;
		        try {
		            icBuilder = icFactory.newDocumentBuilder();
		            Document doc = icBuilder.newDocument();
		        Element mainRootElement = doc.createElementNS("!DOCTYPE MODIFYLMN SYSTEM","MODIFYLMN.dtd");
		            doc.appendChild(mainRootElement); 
		            Node MODIFYLMN = doc.getElementsByTagName("MODIFYLMN").item(0);
		            NamedNodeMap attr = MODIFYLMN.getAttributes();
					Node nodeAttr = attr.getNamedItem("Format  rev="H"/");
					nodeAttr.setTextContent("");
		        }
		        }
		});
		btnRun.setBounds(185, 30, 89, 23);
		frame.getContentPane().add(btnRun);
		
		textField = new JTextField();
		textField.setBounds(29, 31, 86, 20);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("    uname");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 13));
		lblNewLabel.setBounds(30, 11, 85, 14);
		frame.getContentPane().add(lblNewLabel);
		
		Panel panel = new Panel();
		panel.setBounds(102, 77, 231, 129);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		textField_1 = new JTextField();
		textField_1.setBounds(10, 11, 44, 20);
		panel.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(10, 50, 44, 20);
		panel.add(textField_2);
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(10, 99, 44, 20);
		panel.add(textField_3);
		textField_3.setColumns(10);
		
		textField_4 = new JTextField();
		textField_4.setBounds(78, 11, 51, 20);
		panel.add(textField_4);
		textField_4.setColumns(10);
		
		textField_5 = new JTextField();
		textField_5.setBounds(78, 50, 51, 20);
		panel.add(textField_5);
		textField_5.setColumns(10);
		
		textField_6 = new JTextField();
		textField_6.setBounds(78, 99, 51, 20);
		panel.add(textField_6);
		textField_6.setColumns(10);
		
		textField_7 = new JTextField();
		textField_7.setBounds(161, 11, 60, 20);
		panel.add(textField_7);
		textField_7.setColumns(10);
		
		textField_8 = new JTextField();
		textField_8.setBounds(160, 50, 60, 20);
		panel.add(textField_8);
		textField_8.setColumns(10);
		
		textField_9 = new JTextField();
		textField_9.setBounds(162, 99, 55, 20);
		panel.add(textField_9);
		textField_9.setColumns(10);
		
		JLabel lblNewLabel_1 = new JLabel("emaxt_X");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNewLabel_1.setBounds(10, 81, 74, 14);
		frame.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("emaxt_Y");
		lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNewLabel_2.setBounds(10, 120, 65, 14);
		frame.getContentPane().add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("emaxt_W");
		lblNewLabel_3.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblNewLabel_3.setBounds(10, 172, 65, 14);
		frame.getContentPane().add(lblNewLabel_3);
	}
	
}



NB: I put also GUI for my application in attachement

Thanks
 
 http://files.engineering.com/getfile.aspx?folder=ae9efc26-e151-4c54-b9a8-d6149600ceae&file=XML.rar
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top