Hirdetés
Új hozzászólás Aktív témák
-
artiny
őstag
a toXml az emloyee ban igy nez ki most,
public String toXml() {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();Document doc = db.newDocument();
Element employeee = doc.createElement("employee");
doc.appendChild(employeee);Element employee = doc.createElement("employee");
employee.setAttribute("rodneCislo", String.valueOf(rodneCislo));
employee.appendChild(employeee);Element nameE = doc.createElement("meno");
employee.appendChild(nameE);
Text nameEHodnota = doc.createTextNode(this.name);
nameE.appendChild(nameEHodnota);Element oddelenieE = doc.createElement("oddelenie");
employee.appendChild(oddelenieE);
Text oddelenieEHodnota = doc.createTextNode(this.oddelenie);
oddelenieE.appendChild(oddelenieEHodnota);TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("xmldoc.xml"));
t.transform(source, result);
return result.toString();} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;}
return null; a netbeans rakta be, ha ide is a return result.toString(); raktam akkor hibat irt,ha nem volt akkor pedig hianyzott a toXml nek a return statement.
xml.append(employee.toXml()); most nem jelez pirossan."Ja és még valami, ne itt rakd az XML-t fájlba, hanem az oraj osztályban."
TransformerFactory tf = TransformerFactory.newInstance();
Transformer t = tf.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("xmldoc.xml"));
t.transform(source, result);
return result.toString();
-akkor ez a resze a toXml nek nem ide valo hanem az orej osztalyba,ide:public String toXml() {
StringBuilder xml = new StringBuilder();
if ( this.emp!=null && !this.emp.isEmpty() ) {
for (Employee employee: this.emp) {
// employee to xml, ahogy tetszik.
xml.append(employee.toXml());
}
}
return xml.toString();
}
Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- Samsung Galaxy A23 5G / 4/128GB / Kártyafüggetlen / 12 Hó Garancia
- Telefon felvásárlás!! Honor 200 Lite, Honor 200, Honor 200 Pro, Honor 200 Smart
- BESZÁMÍTÁS! MSI B550M R5 5600X 16GB DDR4 512GB SSD RTX 3070 8GB Lian Li Lancool 207 GIGABYTE 750W
- Felsőkategóriás AMD Gamer PC-Számítógép! Beszámítás! R7 9800X3D / 9070XT / 32GB DDR5 / 2TB SSD!
- ÁRGARANCIA!Épített KomPhone i9 14900KF 64GB RAM RTX 5090 32GB GAMER PC termékbeszámítással
Állásajánlatok
Cég: Laptopszaki Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


