XML.......
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 = ?.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....
liveurlife
Designing an XML depends on how u retrieve and insert data. My suggetion for the XML is as follows.
There should be one node(order) which describes all the details of the piza order.
All the details regarding the order, customer details, pizza description should be inside that node.
This helps to retrive full details of the order .
<?xml version="1.0" encoding="Cp1252"?>
<pizza>
<order>
<name>Name</name>
<address> Kitchen2 </address>
<phoneNumber> 0625678800 </phoneNumber>
<description>
<size> small </size>
<price> $10 </price>
<crust> thin </crust>
<toppingtype>meat </toppingtype>
<type>red onion </type>
</description>
</order>
</pizza>
What if you order more than one pizza?
I would do it something like this:
<order>
<name>Name</name>
<address> Kitchen2 </address>
<phoneNumber> 0625678800 </phoneNumber>
<pizza>
<size> small </size>
<price> $10 </price>
<crust> thin </crust>
<toppingtype>meat </toppingtype>
<type>red onion </type>
</pizza>
<pizza>
<size> large </size>
<price> $16 </price>
<crust> thick </crust>
<toppingtype>meat </toppingtype>
<type>red onion </type>
</pizza>
</order>
Then you could have the size and crust as attributes in the element <pizza>
But then of course... the correct answer to this question is "This is no f--*** Java question..." ;-)
null
Lajma at 2007-7-8 2:02:11 >

I will create an XML like below
<?xml version=?.0?>
<pizza>
<order>
<id>1</id>
<name> My Pizza </name>
<address> Kitchen </address>
</order>
<order>
<id>2</id>
<name> My Pizza </name>
<address> Kitchen </address>
</order>
</pizza>
Cheers
Message was edited by:
astelaveesta
I think this is closer to what it should be, but there are plenty of other possibilities, choose one you like, or better, come up with your own.
<?xml version=1.0?>
<order>
<name>Name</name>
<address> Kitchen2 </address>
<phoneNumber> 0625678800 </phoneNumber>
<pizza>
<size> small </size>
<price> $10 </price>
<crust> thin </crust>
<toppings>
<meat>pepperoni</meat>
<veg>red onion</veg>
<veg>mushroom</veg>
</toppings>
</pizza>
<pizza>
<size>large</size>
<price>$16</price>
<crust>thick</crust>
<toppings>
<meat>beef</meat>
<veg>onion</veg>
<veg>green pepper</veg>
</toppings>
</pizza>
</order>
~Tim
> I will create an XML like below
>
> <?xml version=?.0?>
>
> <pizza>
>
> <order>
>
> <order>1</order>
> <name> My Pizza </name>
> <address> Kitchen </address>
>
> </order>
>
> <order>
>
> <order>2</order>
> <name> My Pizza </name>
> <address> Kitchen </address>
>
> </order>
>
> </pizza>
Cheers
In this one, you don't say anything about the actuall pizzas... That is ok... more freedom to the chef!
Lajma at 2007-7-8 2:02:11 >

> In this one, you don't say anything about the actuall> pizzas... That is ok... more freedom to the chef!Hey Lajm, this is not a forum to describe abt pizzas. I jus gave a structure. Rest OP can do. Cheers
Hi,
Thanks for your help everyone!!
Is this good? Or do I have it all stuffed up?
PHP Code:
<?xml version = ?.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>
Thanks again
It will be better if u give an <id> to each <order>, jus like primary key in a table. Cheers
> Hi,
>
> Thanks for your help everyone!!
>
> Is this good? Or do I have it all stuffed up?
>
> PHP Code:
>
> <?xml version = ?.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>
>
>
> Thanks again
Thanks! people i'l try out the suggestions!
Well, quite...
Think like this:
A customer calls the pizza plaze to place an order
- Start element <Order>
The customer tells his name
- Start element <Customer>
- Add element <Name>customer name</Name>
his address
- Add element <Address>customer address</Address>
his phonenumber
- Add element <PhoneNumber>Phno</PhoneNumber>
- End element </Customer>
The customer now tells the pizza guy what sort of pizza OR pizzas he like to have
"I like to have a small pizza..."
- start element <Pizza>
"... with a thin crust...>
- add element <Crust>thin</Crust> [or set attribute crust="thin" in element <Pizza>]
- add element <Price>10</Price> [or set attribute price="10" in element <Pizza>]
"... and I like to have beef and red onions on it."
- start element <toppings>
- add element <meat>beef</meet>
- add element <veggies>red onion</veggies>
- end element </toppings>
- end element </Pizza>
The pizza guy asks "Anything more?"
If the customer say "No"
- end element <Order>
or if customer says "Yes, onne large thincrusted with chicken"
- do the <Pizza>-stuff again.
One order can contain more than one pizza but only one customer.
When coding this, it is easy to create small beans that creates the xml-elements for you if you break it down like this.
Then I preffer to use attributes when it is a fixed amount of values that are possible to use in as value.
Lajma at 2007-7-8 2:02:11 >

