09.XML Processing Exercises
09.XML Processing Exercises
This document defines the exercise assignments for the Databases Advanced - Entity Framework course @ SoftUni
You can check your solutions in Judge
Users should have many Products sold and many Products bought.
Products should have many Categories.
Categories should have many Products.
CategoryProducts should map Products and Categories.
2. Import Data
Query 1. Import Users
NOTE: You will need method public static string ImportUsers(ProductShopContext context, string
inputXml) and public StartUp class.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Some of the names will be null, so you don't have to add them to the database. Just skip the record and continue.
Import the categories and products ids from the provided file "categories-products.xml". If provided
CategoryId or ProductId doesn't exist, skip the whole entry!
Get all products in a specified price range between 500 and 1000 (inclusive). Order them by price (from lowest to
highest). Select only the product name, price and the full name of the buyer. Take top 10 records.
products-in-range.xml
<?xml version="1.0" encoding="utf-16"?>
<Products>
<Product>
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Get all users who have at least 1 sold item. Order them by the last name, then by the first name. Select the
person's first and last name. For each of the sold products, select the product's name and price. Take top 5 records.
users-sold-products.xml
<?xml version="1.0" encoding="utf-16"?>
<Users>
<User>
<firstName>Almire</firstName>
<lastName>Ainslee</lastName>
<soldProducts>
<Product>
<name>Ampicillin</name>
<price>674.63</price>
</Product>
<Product>
<name>Strattera</name>
<price>658.54</price>
</Product>
<Product>
<name>Aspergillus repens</name>
<price>1231.42</price>
</Product>
</soldProducts>
</User>
...
</Users>
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
categories-by-products.xml
<?xml version="1.0" encoding="utf-16"?>
<Categories>
<Category>
<name>Garden</name>
<count>23</count>
<averagePrice>800.150869</averagePrice>
<totalRevenue>18403.47</totalRevenue>
</Category>
<Category>
<name>Weapons</name>
<count>22</count>
<averagePrice>671.073181</averagePrice>
<totalRevenue>14763.61</totalRevenue>
</Category>
...
</Categories>
Select users who have at least 1 sold product. Order them by the number of sold products (from highest to lowest).
Select only their first and last name, age, count of sold products and for each product - name and price sorted by
price (descending). Take top 10 records.
Follow the format below to better understand how to structure your data.
users-and-products.xml
<Users>
<count>54</count>
<users>
<User>
<firstName>Dale</firstName>
<lastName>Galbreath</lastName>
<age>31</age>
<SoldProducts>
<count>9</count>
<products>
<Product>
<name>Fair Foundation SPF 15</name>
<price>1394.24</price>
</Product>
<Product>
<name>Finasteride</name>
<price>1374.01</price>
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Car Dealer
1. Setup Database
A car dealer needs information about cars, their parts, parts suppliers, customers and sales.
Cars have Make, Model, TraveledDistance in kilometers.
Parts have Name, Price and Quantity.
Supplier has a Name and info whether they supply imported parts.
Customer has a Name, BirthDate and info whether they are a young driver (young driver is a driver that
has less than 2 years of experience. Those customers get an additional 5% off for the sale.).
Sale has a Car, Customer and a Discount percentage.
A Price of a Car is formed by the total price of its Parts.
A Car has many Parts and one Part can be placed in many Cars.
One Supplier can supply many Parts and each Part can be delivered by only one Supplier.
In one Sale, only one Car can be sold to only one Customer.
A Customer can buy many Cars.
2. Import Data
Import data from the provided files ("suppliers.xml", "parts.xml", "cars.xml", "customers.xml").
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Import the parts from the provided file "parts.xml". If the supplierId doesn't exist, skip the record.
Import the cars from the provided file "cars.xml". Select unique car part ids. If the partId doesn't exist, skip the
Part record.
Import the sales from the provided file "sales.xml". If car doesn't exist, skip whole entity.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
cars.xml
<?xml version="1.0" encoding="utf-16"?>
<cars>
<car>
<make>BMW</make>
<model>1M Coupe</model>
<traveled-distance>39826890</traveled-distance>
</car>
<car>
<make>BMW</make>
<model>E67</model>
<traveled-distance>476830509</traveled-distance>
</car>
<car>
<make>BMW</make>
<model>E88</model>
<traveled-distance>27453411</traveled-distance>
</car>
...
</cars>
Get all cars from make BMW and order them by model alphabetically and by traveled distance descending.
bmw-cars.xml
<cars>
<car id="26" model="1M Coupe" traveled-distance="39826890" />
<car id="28" model="E67" traveled-distance="476830509" />
<car id="24" model="E88" traveled-distance="27453411" />
...
</cars>
Get all suppliers that do not import parts from abroad. Get their id, name and the number of parts they can offer
to supply.
local-suppliers.xml
<?xml version="1.0" encoding="utf-16"?>
<suppliers>
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Get all cars along with their list of parts. For the car get only make, model and traveled distance and for
the parts get only name and price and sort all parts by price (descending). Sort all cars by traveled distance
(descending) and then by the model (ascending). Select top 5 records.
cars-and-parts.xml
<?xml version="1.0" encoding="utf-16"?>
<cars>
<car make="Opel" model="Astra" traveled-distance="516628215">
<parts>
<part name="Tappet" price="300.29" />
<part name="Front Left Side Door Glass" price="100.92" />
<part name="Fan belt" price="10.99" />
</parts>
</car>
...
</cars>
Get all customers that have bought at least 1 car and get their names, bought cars count and total spent money on
cars. Order the result list by total spent money (descending). Don't forget that young drivers get a discount!
customers-total-sales.xml
<?xml version="1.0" encoding="utf-16"?>
<customers>
<customer full-name="Emmitt Benally" bought-cars="1" spent-money="5044.10" />
<customer full-name="Garret Capron" bought-cars="1" spent-money="3327.10" />
<customer full-name="Cinthia Lasala" bought-cars="1" spent-money="3173.09" />
...
</customers>
Get all sales with information about the car, customer and price of the sale with and without discount. Don't take
under consideration the young driver discount!
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
sales-discounts.xml
<?xml version="1.0" encoding="utf-16"?>
<sales>
<sale>
<car make="Opel" model="Omega" traveled-distance="109910837" />
<discount>30.00</discount>
<customer-name>Zada Attwoood</customer-name>
<price>330.97</price>
<price-with-discount>231.68</price-with-discount>
</sale>
...
</sales>
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.