.


:




:

































 

 

 

 


XML-




, .


(Element, Attribute, Document, Text .) , XML- . JDOM.

Element

, XML- :

Element addContent(Content child) ;

Element addContent(int index, Content child) ;

Element addContent(String str) ;

Element setAttribute(Attribute attribute) ;

Element setAttribute(String name, String value) ;

Element setContent(Content child) , ;

Element setContent(int index, Content child) , ;

Element setName(String name) ;

Element setText(String text) .

Text

Text XML-:

void append(String str) ;

void append(Text text) Text, ;

Text setText(String str) .

Attribute

Attribute , :

Attribute setAttributeType(int type) ;

Attribute setName(String name) ;

Attribute setValue(String value) .

XML- . XML- XMLOutputter.

/* # 10: JDOM:

JDOMLogic.java */

package chapt16.saver.dom;

import java.io.FileOutputStream;

import java.io.IOException;

import java.util.List;

import java.util.Iterator;

import org.jdom.Document;

import org.jdom.Element;

import org.jdom.output.XMLOutputter;

import chapt16.entity.Student;

 

public class JDOMLogic {

public static Document create(List<Student> list) { // <studentsnew>

Element root = new Element("studentsnew");

Iterator<Student> studentIterator =

list.iterator();

while (studentIterator.hasNext()) {

Student student = studentIterator.next();

// <student>

Element studentElement = new Element("student");

//

studentElement.setAttribute("login",

student.getLogin());

studentElement.setAttribute("phone",

student.getTelephone());

 

Element faculty = new Element("faculty");

faculty.setText(student.getFaculty());

// <faculty> <student>

studentElement.addContent(faculty);

 

Element name = new Element("name");

name.setText(student.getName());

studentElement.addContent(name);

// <address>

Element addressElement = new Element("address");

Student.Address address = student.getAddress();

 

Element country = new Element("country");

country.setText(address.getCountry());

addressElement.addContent(country);

 

Element city = new Element("city");

city.setText(address.getCity());

addressElement.addContent(city);

 

Element street = new Element("street");

street.setText(address.getStreet());

// <street> <address>

addressElement.addContent(street);

// <address> <student>





:


: 2016-04-03; !; : 329 |


:

:

, .
==> ...

1761 - | 1668 -


© 2015-2024 lektsii.org - -

: 0.012 .