L
Lana
Hello all!
I need to add another element to an XML file along with its content, but
encountered a problem.
I tried with the code provided, but it happens so that i can't run the
program from my jbuilder.
As it has the main method, i dont understand why..
Any help would do.
Thanx in advance
greetings
)
the code:
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import java.io.*;
import org.jdom.output.*;
class Dodaj
extends Element {
double unos;
double konkpon;
double konkuto;
public void main(String[] args) {
String filename = "jdom.xml";
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(new File(filename));
Element root = doc.getRootElement();
// Output the document, use standard formatter
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, System.out);
//saving XML document
File outputFile = new File("jdom.xml");
FileOutputStream out = new FileOutputStream(outputFile);
fmt.output(doc, out);
out.flush();
out.close();
unos = 5;
konkpon = 5;
System.out.println(unos);
if (unos == konkpon) {
Element element = new Element("Year");
Element element2 = new Element("day index=\"monday\"");
Element element3 = new Element("hour index=\"10-12\"");
element3.setText("Konkurentno labos");
element.addContent(element2);
element2.addContent(element3);
}
else if (unos == konkuto) {
Element element = new Element("Year");
Element element2 = new Element("day index=\"tuesday\"");
Element element3 = new Element("hour index=\"9-11\"");
element3.setText("Konkurentno labos");
element.addContent(element2);
element2.addContent(element3);
}
}
// indicates a well-formedness error
catch (JDOMException e) {
System.out.println(filename + " is not well-formed.");
System.out.println(e.getMessage());
}
catch (IOException e) {
System.out.println(e);
}
}
}
I need to add another element to an XML file along with its content, but
encountered a problem.
I tried with the code provided, but it happens so that i can't run the
program from my jbuilder.
As it has the main method, i dont understand why..
Any help would do.
Thanx in advance
greetings
the code:
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import java.io.*;
import org.jdom.output.*;
class Dodaj
extends Element {
double unos;
double konkpon;
double konkuto;
public void main(String[] args) {
String filename = "jdom.xml";
SAXBuilder builder = new SAXBuilder();
try {
Document doc = builder.build(new File(filename));
Element root = doc.getRootElement();
// Output the document, use standard formatter
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, System.out);
//saving XML document
File outputFile = new File("jdom.xml");
FileOutputStream out = new FileOutputStream(outputFile);
fmt.output(doc, out);
out.flush();
out.close();
unos = 5;
konkpon = 5;
System.out.println(unos);
if (unos == konkpon) {
Element element = new Element("Year");
Element element2 = new Element("day index=\"monday\"");
Element element3 = new Element("hour index=\"10-12\"");
element3.setText("Konkurentno labos");
element.addContent(element2);
element2.addContent(element3);
}
else if (unos == konkuto) {
Element element = new Element("Year");
Element element2 = new Element("day index=\"tuesday\"");
Element element3 = new Element("hour index=\"9-11\"");
element3.setText("Konkurentno labos");
element.addContent(element2);
element2.addContent(element3);
}
}
// indicates a well-formedness error
catch (JDOMException e) {
System.out.println(filename + " is not well-formed.");
System.out.println(e.getMessage());
}
catch (IOException e) {
System.out.println(e);
}
}
}