Hey,

I came across this question, this is the 1st time I write a XML file, and I have no idea if my work is correct, or if thats how its supposed to be.......please give me your feedback:

Consider the following XML file that describes a pizza:
An order for a Pizza in a restaurant, stores the name, address, and the phone number of the customer. It stores also the description of one or more pizzas. A pizza has a size (small priced at $10, medium at $13 and large at $16), a crust type (thin or thick) and one or more toppings. The toping could be meat (beef or chicken), vegetable (red onion or cilantro).

Create an XML file that describes two different order for two different pizza.


this is what i did:

<?xml version = ”1.0” ?>
<Pizza>
<name> My Pizza </name>
<address> Kitchen </address>
<phoneNumber> 065432198 </phoneNumber>
<description> 
<size> small </size>
<price> $10 </price>
<crust> thin </crust>
<topping>
<meat>beef </meat>
<meat>chicken</meat>
<vegetable> red onion </vegetable>
<vegetable> cilantro </vegetable>
</topping>
</description>
<name> His Pizza </name>
<address> Kitchen2 </address>
<phoneNumber> 0625678800 </phoneNumber>
<description> 
<size> large </size>
<price> $16 </price>
<crust> thick </price>
<topping>
<meat>beef </meat>
<meat>chicken<meat>
<vegetable> red onion </vegetable>
<vegetable> cilantro </vegetable>
</topping>
</description>
</Pizza>

Thanks in advance....

itchap

poor choice of tag names, and I'd put the delivery information in its own container structure.
What you call "description" is really a pizza.

It will work fine but as stated above, try to follow better naming guidelines. <Pizza> in your case describes a list of what looks to be orders...whereas <description> IS a description, but of a Pizza. You should also possibly consider enclosing each order in a seperate tag, possibly <order>. The way you have it now the Name, Address, and Phone # are not quite mapped to the corresponding pizza.

Regards,

Tyler S. Breton

that's not a probably, that's a MUST.
There's no guarantee the fields from an XML file will reach your code in the same order in which they exist in that file, so to prevent things from getting messed up along the way they must be grouped in a logical and correct hierarchy.

Hi guys,

Thanks for the tips!! Is this better??????

<?xml version = ”1.0” ?>
<Order>
<Pizza>
<Customer>
<name> My Pizza </name>
<address> Kitchen </address>
<phoneNumber> 065432198 </phoneNumber>
</Customer>
<description> 
<size> small </size>
<price> $10 </price>
<crust> thin </crust>
<topping>
<meat>beef </meat>
<meat>chicken</meat>
<vegetable> red onion </vegetable>
<vegetable> cilantro</vegetable>
</topping>
</description>
</Pizza>
</Order>
 
<Order>
<Pizza>
<Customer>
<name> His Pizza </name>
<address> Kitchen2 </address>
<phoneNumber> 0625678800 </phoneNumber>
</Customer>
<description> 
<size> large </size>
<price> $16 </price>
<crust> thick </price>
<topping>
<meat>beef </meat>
<meat>chicken<meat>
<vegetable> red onion </vegetable>
<vegetable> cilantro</vegetable>
</topping>
</description>
</Pizza>
</Order>

Looking forward to hear your feedback.......thanks!

itchap

That's not valid XML, you have more than one root element in the file.
Apart from that, it looks a lot better.

To fix it, create a new document root containing all the Order elements, something like "Orders".

You may want to change all tag names to lower case too. While not required it is convention to use only lowercase tag and attribute names.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.