Электронный магазин на Java и XML

         

Преобразование Product в XML (Product.java)



Листинг 6.27. Преобразование Product в XML (Product.java)

public void toXML( XMLWriter writer ) throws IOException { writer.write( "<product id='" + id + "'" );
if( keywords != null ) writer.write( " keywords='" + keywords + "'" );
writer.writeln( ">
" );
writer.indent();
writer.writeln( "<name>
" + name + "</name>
" );
for( int i = 0; i < authors.size();
i++ ) { writer.writeln( "<author>
" + authors.elementAt( i ) + "</author>
" );
} for( int i = 0; i < artists.size();
i++ ) { writer.writeln( "<artist>
" + artists.elementAt( i ) + "</artist>
" );
} writer.writeln( "<description>
" + description + "</description>
" );
writer.writeln( "<price>
" + price + "</price>
" );
writer.writeln( "<quantity_in_stock>
" + quantityInStock + "</quantity_in_stock>
" );
for( int i = 0; i < images.size();
i++ ) { Image image = (Image)images.elementAt( i );
image.toXML( writer );
} if( onSaleDate != null ) onSaleDate.toXML( writer );
for( int i = 0; i < clips.size();
i++ ) { Clip clip = (Clip)clips.elementAt( i );
clip.toXML( writer );
} writer.unindent();
writer.writeln( "</product>
" );
} }



Содержание раздела