Ú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?:))
- Új, bontatlan Kingston FURY Beast RGB 32GB (2x16GB) DDR5 6400MHz CL32 EXPO/XMP - 2 év garancia
- PS5 Pro+Sony Pulse 3D+Játék
- Bomba ár! HP EliteBook 840 G6 - i7-8GEN I 16GB I 512GB SSD I 14" FHD I HDMI I Cam I W11 I Gari!
- Bomba ár! Lenovo X13 G2i - i5-1135G7 I 16GB I 256SSD I 13,3" WUXGA Touch I W11 I Cam I Gari!
- Bomba ár! Lenovo X1 Carbon G7: i5-8265U I 8GB I 256SSD I 14" FHD Touch I HDMI I Cam I W11 I Gari!
- AKCIÓ! Törött Apple iMac 19.2 i5-8500 Radeon Pro 560X 4GB 16GB 256GB SSD 21.5" 4K Retina
- SteelSeries Apex Gaming billentyűzet, német, RGB
- Telefon felvásárlás!! Samsung Galaxy S21/Samsung Galaxy S21+/Samsung Galaxy S21 Ultra
- Bomba ár! Lenovo ThinkPad Yoga 260 - i5-G6 I 8GB I 256SSD I 12,5" Touch I W11 I Cam I Gari!
- LG 55G4 - 55" OLED evo - 4K 144Hz & 0.1ms - MLA Plus - 3000 Nits - NVIDIA G-Sync - FreeSync Premium
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

