Home » Community » Newbie corner » XML exercise
XML exercise [message #35990] |
Mon, 16 April 2012 20:49 |
idkfa46
Messages: 155 Registered: December 2011
|
Experienced Member |
|
|
Good evening guys,
I can’t understand how can I correctly use XML. Looking into bazar I haven’t found a examples so I thought about a little “exercise” maybe useful for newbies about Parsing and XmlNode
Here a little example of what I’m planning to create:
This little program have a droplist where users can select different type of cars. For each car, the program show select1, select2 and select3 values.
A possible Xml structure could be:
<car>A</car>
<value>
<Select1 value="1"/>
<Select2 value="2"/>
<Select3 value="3"/>
</value>
<car>B</car>
<value>
<Select1 value="4"/>
<Select2 value="5"/>
<Select3 value="6"/>
</value>
So, Selecting “A” from the DropList menu the program will show
Select1 = 1,
Select2 = 2,
Select3 =3,
and selecting “B”
Select1 = 4,
Select2 = 5,
Select3 = 6.
-The first step will be to code it for reading XLM structure and show stored values.
-Then, the second step will be to allow user adding/deleting cars with their own values.
The AddressBook example in bazar show the possibility to store datas but it creates a new xml everytime, so the problem is a bit different.
Thanks for your support
Regards,
Matteo
here the layout
LAYOUT(prova4Layout, 188, 240)
ITEM(Label, dv___0, SetLabel(t_("Car :")).LeftPosZ(10, 55).TopPosZ(40, 21))
ITEM(Label, dv___1, SetLabel(t_("Select 1 :")).LeftPosZ(10, 55).TopPosZ(108, 21))
ITEM(Label, dv___2, SetLabel(t_("Select 2 :")).LeftPosZ(10, 55).TopPosZ(134, 21))
ITEM(Label, dv___3, SetLabel(t_("Select 3 :")).LeftPosZ(10, 55).TopPosZ(162, 21))
ITEM(DropList, dl, LeftPosZ(72, 103).TopPosZ(41, 19))
ITEM(StaticText, dv___5, SetText(t_("Setting :")).SetFont(StdFontZ(16).Bold()).LeftPosZ(10, 166).TopPosZ(7, 25))
ITEM(StaticText, dv___6, SetText(t_("Details :")).SetFont(StdFontZ(16).Bold()).LeftPosZ(10, 164).TopPosZ(74, 25))
ITEM(EditDouble, select1, LeftPosZ(72, 102).TopPosZ(110, 19))
ITEM(EditDouble, select2, LeftPosZ(72, 102).TopPosZ(136, 19))
ITEM(EditDouble, select3, LeftPosZ(72, 102).TopPosZ(163, 19))
ITEM(Button, dv___10, SetLabel(t_("NEW")).LeftPosZ(7, 77).TopPosZ(200, 23))
ITEM(Button, dv___11, SetLabel(t_("DELETE")).LeftPosZ(93, 79).TopPosZ(200, 23))
END_LAYOUT
-
Attachment: Cattura.JPG
(Size: 19.57KB, Downloaded 470 times)
[Updated on: Wed, 18 April 2012 09:23] Report message to a moderator
|
|
|
|
|
Re: XML exercise [message #36090 is a reply to message #36080] |
Thu, 26 April 2012 15:49 |
Lance
Messages: 527 Registered: March 2007
|
Contributor |
|
|
Quote: |
The AddressBook example in bazar show the possibility to store datas but it creates a new xml everytime, so the problem is a bit different.
|
The example has everything you need to do what you want. You can skip the FileSel dialog part and insert a fixed file name so that it doesn't "create a new xml everytime" (if I got it right).
If I do it, XML is good for storage and transportation of information beyond your application. Within your application, you should be better off to store it in a, eg sorted Vector, for better performance.
so:
1. program start, read(parse) XML database, and store car info in a more accessible way;
2. do add/edit/delete as you do in any other data manipulation application. XML is not relevant here
3. when close or explicit save requested, check if data is changed, if yes, save to XML.
you can already do 1 and 3 with reference to AddressXML, so just figure out how you should do 2.
HTH
|
|
|
Re: XML exercise [message #36182 is a reply to message #36090] |
Wed, 09 May 2012 12:27 |
Wolfgang
Messages: 146 Registered: November 2011 Location: Germany
|
Experienced Member |
|
|
but isn't it the false structure of xml should be used...?
I believe this will be a better one:
<vehicle>
<car>A</car>
<value num="1">10</value>
<value num="2">11</value>
<value num="3">12</value>
</vehicle>
OR
<vehicle>
<car>A</car>
<values>
<a>10</a>
<b>11</b>
<c>12</c>
</values>
</vehicle>
depending what you want to realize...
just my two cents
|
|
|
Goto Forum:
Current Time: Sat May 04 16:08:43 CEST 2024
Total time taken to generate the page: 0.03156 seconds
|