Bakalskaya_E.D._PIbd_31_MiAKD/miakd/XMLfromSQLquery.xml

158 lines
5.4 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="styles_animals_SQL.xslt"?>
<animals>
<animal>
<animal_id>1</animal_id>
<name>Слон</name>
<width>3.2</width>
<height>4</height>
<weight>5400</weight>
<color>Серый</color>
<food>Трава, тростник</food>
<averageIntake>около 150</averageIntake>
<habitat>Саванна</habitat>
<interestingFact>Слоны - самые большие животные на Земле (на суше)</interestingFact>
</animal>
<animal>
<animal_id>2</animal_id>
<name>Пингвин</name>
<width>0.4</width>
<height>1.1</height>
<weight>30</weight>
<color>Черно-белые, иногда фиолетово-белые</color>
<food>Рыба</food>
<averageIntake>2</averageIntake>
<habitat>Антарктика</habitat>
<interestingFact>Пингвины-родители по очереди высиживают яйца, пока второй партнер уходит на охоту за рыбой</interestingFact>
</animal>
<animal>
<animal_id>3</animal_id>
<name>Тигр</name>
<width>1.2</width>
<height>1</height>
<weight>220</weight>
<color>Оранжевый с черными полосами</color>
<food>Мясо</food>
<averageIntake>10</averageIntake>
<habitat>Леса, саванны</habitat>
<interestingFact>Тигры могут проплывать до 6 км за один раз</interestingFact>
</animal>
<animal>
<animal_id>4</animal_id>
<name>Панда</name>
<width>0.8</width>
<height>0.7</height>
<weight>100</weight>
<color>Черно-белый</color>
<food>Бамбук</food>
<averageIntake>15</averageIntake>
<habitat>Горные леса Китая</habitat>
<interestingFact>Панды проводят до 14 часов в день, поедая бамбук</interestingFact>
</animal>
<animal>
<animal_id>5</animal_id>
<name>Белый медведь</name>
<width>1.5</width>
<height>1.6</height>
<weight>450</weight>
<color>Белый</color>
<food>Морские млекопитающие</food>
<averageIntake>7</averageIntake>
<habitat>Арктика</habitat>
<interestingFact>Белые медведи могут нюхать добычу на расстоянии до 30 км</interestingFact>
</animal>
<animal>
<animal_id>6</animal_id>
<name>Фламинго</name>
<width>0.3</width>
<height>1.5</height>
<weight>3</weight>
<color>Розовый</color>
<food>Мелкие рыбы и водоросли</food>
<averageIntake>0,5</averageIntake>
<habitat>Соленые озера и лагуны</habitat>
<interestingFact>Цвет перьев фламинго зависит от их диеты</interestingFact>
</animal>
</animals>
<!--drop table if exists animals;
drop table color;
drop table if exists habitat;
create table color(
id serial primary key,
name varchar(255) not null
);
create table habitat(
id serial primary key,
name varchar(255) not null
);
create table animals(
id serial primary key,
name VARCHAR(255) NOT NULL,
width FLOAT,
height FLOAT,
weight INTEGER,
color_id INTEGER,
food varchar(255) not null,
averageIntake varchar(255) not null,
habitat_id INTEGER,
interesting_fact TEXT,
FOREIGN KEY (color_id) REFERENCES color(id),
FOREIGN KEY (habitat_id) REFERENCES habitat(id)
);
INSERT INTO color (name) VALUES
('Серый'),
('Черно-белые, иногда фиолетово-белые'),
('Оранжевый с черными полосами'),
('Черно-белый'),
('Белый'),
('Розовый');
INSERT INTO habitat (name) VALUES
('Саванна'),
('Антарктика'),
('Леса, саванны'),
('Горные леса Китая'),
('Арктика'),
('Соленые озера и лагуны');
INSERT INTO animals (name, width, height, weight, color_id, food, averageIntake, habitat_id, interesting_fact) VALUES
('Слон', 3.2, 4.0, 5400, 1, 'Трава, тростник', 'около 150', 1, 'Слоны - самые большие животные на Земле (на суше)'),
('Пингвин', 0.4, 1.1, 30, 2, 'Рыба', '2', 2, 'Пингвины-родители по очереди высиживают яйца, пока второй партнер уходит на охоту за рыбой'),
('Тигр', 1.2, 1.0, 220, 3, 'Мясо', '10', 3, 'Тигры могут проплывать до 6 км за один раз'),
('Панда', 0.8, 0.7, 100, 4, 'Бамбук', '15', 4, 'Панды проводят до 14 часов в день, поедая бамбук'),
('Белый медведь', 1.5, 1.6, 450, 5, 'Морские млекопитающие', '7', 5, 'Белые медведи могут нюхать добычу на расстоянии до 30 км'),
('Фламинго', 0.3, 1.5, 3, 6, 'Мелкие рыбы и водоросли', '0,5', 6, 'Цвет перьев фламинго зависит от их диеты');
SELECT xmlelement(
name "animals",
xmlagg(
xmlelement(
name "animal",
xmlforest(
animals.id AS "animal_id",
animals.name AS "name",
animals.width AS "width",
animals.height AS "height",
animals.weight AS "weight",
color.name AS "color",
animals.food as "food",
animals.averageIntake as "averageIntake",
habitat.name AS "habitat",
animals.interesting_fact AS "interestingFact"
)
)
)
) AS full_animal_data
FROM animals
JOIN color ON animals.color_id = color.id
JOIN habitat ON animals.habitat_id = habitat.id;-->