-
converting text files to xml
Please help, I have no clue where or how to start.
I have to convert the below text file into xml and i have no clue how to.
The description file refers to handlers like:
FileNameNotify
LoadButtonNotify
ImageMagnificationNotify
ColorApplyButtonNotify
ColorResetButtonNotify
QuitButtonNotify
You can represent these simply by a function/method taking no
parameters
but printing out its own name to standard output when called.
========= Description file ================
(
:type :text-field
:name DirectoryPathField
wner ControlArea
:x 5
:y 5
:width 160
:height 32
:foreground-color ""
:text-type :alphanumeric
:label "Directory path :"
:label-type :string
:value-x 5
:value-y 22
:layout-type :vertical
:value-length 20
:stored-length 150
:read-only nil
:notify-handler nil
)
(
:type :text-field
:name FileNameField
wner ControlArea
:x 5
:y 45
:width 165
:height 32
:foreground-color ""
:text-type :alphanumeric
:label "Image source file name:"
:label-type :string
:value-x 5
:value-y 62
:layout-type :vertical
:value-length 20
:stored-length 80
:read-only nil
:notify-handler FileNameNotify
)
(
:type :button
:name LoadButton
wner ControlArea
:x 10
:y 85
:constant-width nil
:button-type :normal
:width 51
:height 19
:foreground-color ""
:label "LOAD"
:label-type :string
:menu nil
:notify-handler LoadButtonNotify
)
(
:type :text-field
:name LoadAmountField
wner ControlArea
:x 70
:y 85
:width 96
:height 15
:foreground-color ""
:text-type :alphanumeric
:label ""
:label-type :string
:value-x 70
:value-y 85
:layout-type :horizontal
:value-length 12
:stored-length 80
:read-only nil
:notify-handler nil
)
(
:type :message
:name MagnificationHeader
wner ControlArea
:x 5
:y 110
:width 173
:height 13
:foreground-color ""
:label "--Image Magnification--"
:label-type :string
)
(
:type :text-field
:name ImageMagnificationField
wner ControlArea
:x 5
:y 130
:width 167
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "Scale:"
:label-type :string
:value-x 52
:value-y 130
:layout-type :horizontal
:value-length 15
:stored-length 80
:read-only nil
:notify-handler ImageMagnificationNotify
)
(
:type :message
:name ColorBoxHeader
wner ControlArea
:x 5
:y 160
:width 172
:height 13
:foreground-color ""
:label "--Colour Box Selection--"
:label-type :string
)
(
:type :text-field
:name RedLoField
wner ControlArea
:x 5
:y 180
:width 72
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "RLo:"
:label-type :string
:value-x 41
:value-y 180
:layout-type :horizontal
:value-length 4
:stored-length 10
:read-only nil
:notify-handler nil
)
(
:type :text-field
:name RedHiField
wner ControlArea
:x 100
:y 180
:width 71
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "RHI:"
:label-type :string
:value-x 135
:value-y 180
:layout-type :horizontal
:value-length 4
:stored-length 10
:read-only nil
:notify-handler nil
)
(
:type :text-field
:name GreenLoField
wner ControlArea
:x 5
:y 200
:width 72
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "GLo:"
:label-type :string
:value-x 41
:value-y 200
:layout-type :horizontal
:value-length 4
:stored-length 10
:read-only nil
:notify-handler nil
)
(
:type :text-field
:name GreenHiField
wner ControlArea
:x 100
:y 200
:width 71
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "GHi:"
:label-type :string
:value-x 135
:value-y 200
:layout-type :horizontal
:value-length 4
:stored-length 10
:read-only nil
:notify-handler nil
)
(
:type :text-field
:name BlueLoField
wner ControlArea
:x 4
:y 220
:width 72
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "BLo:"
:label-type :string
:value-x 40
:value-y 220
:layout-type :horizontal
:value-length 4
:stored-length 10
:read-only nil
:notify-handler nil
)
(
:type :text-field
:name BlueHiField
wner ControlArea
:x 100
:y 220
:width 71
:height 15
:foreground-color ""
:text-type :alphanumeric
:label "BHi:"
:label-type :string
:value-x 135
:value-y 220
:layout-type :horizontal
:value-length 4
:stored-length 10
:read-only nil
:notify-handler nil
)
(
:type :button
:name ColorboxApplyButton
wner ControlArea
:x 5
:y 250
:constant-width nil
:button-type :normal
:width 56
:height 19
:foreground-color ""
:label "APPLY"
:label-type :string
:menu nil
:notify-handler ColorApplyButtonNotify
)
(
:type :button
:name ColorResetButton
wner ControlArea
:x 100
:y 250
:constant-width nil
:button-type :normal
:width 55
:height 19
:foreground-color ""
:label "RESET"
:label-type :string
:menu nil
:notify-handler ColorResetButtonNotify
)
(
:type :message
:name ContourHeader
wner ControlArea
:x 5
:y 290
:width 174
:height 13
:foreground-color ""
:label "---Contour Extraction---"
:label-type :string
)
(
:type :button
:name QuitButton
wner ControlArea
:x 55
:y 520
:constant-width nil
:button-type :normal
:width 135
:height 19
:foreground-color ""
:label "QUIT APPLICATION"
:label-type :string
:menu nil
:notify-handler QuitButtonNotify
)
)
====== End of Description file ============
Please help
-
Re: converting text files to xml
Basically, you want to split the text file into smaller and smaller chunks
using string methods, and then map the contents at each level to XML tags.
For example, the content within each set of parentheses appears to describe
a set of controls, so you might start by outputing a <controls> element to
contain all the controls. Next, read the content up to the first opening
parenthesis, and write a <control> tag.
The content within each set of parentheses consists of items delimited by
line terminators. Each line is a name/value pair. It looks like those are
separated by tabs, but I can't tell from your example. At any rate, the
process would be, read the line, extract the name and use that as the XML
element name, write the opening tag, extract the value, write that and then
close the tag. Repeat that until you encounter the closing parenthesis that
marks the end of each control. When you find that close the <control> tag.
<controls>
<control>
<type>:text-field</type>
<name>DirectoryPathField</name>
<owner>ControlArea</owner>
<x>5</x>
<y>5</y>
etc.
</control>
repeat to end of file.
</controls>
<xml.@127.0.0.1> wrote in message news:3e4122b7$1@tnews.web.devx.com...
>
> Please help, I have no clue where or how to start.
>
> I have to convert the below text file into xml and i have no clue how to.
>
> The description file refers to handlers like:
>
> FileNameNotify
> LoadButtonNotify
> ImageMagnificationNotify
> ColorApplyButtonNotify
> ColorResetButtonNotify
> QuitButtonNotify
>
> You can represent these simply by a function/method taking no
> parameters
> but printing out its own name to standard output when called.
>
>
> ========= Description file ================
> (
> :type :text-field
> :name DirectoryPathField
> wner ControlArea
> :x 5
> :y 5
> :width 160
> :height 32
> :foreground-color ""
> :text-type :alphanumeric
> :label "Directory path :"
> :label-type :string
> :value-x 5
> :value-y 22
> :layout-type :vertical
> :value-length 20
> :stored-length 150
> :read-only nil
> :notify-handler nil
> )
> (
> :type :text-field
> :name FileNameField
> wner ControlArea
> :x 5
> :y 45
> :width 165
> :height 32
> :foreground-color ""
> :text-type :alphanumeric
> :label "Image source file name:"
> :label-type :string
> :value-x 5
> :value-y 62
> :layout-type :vertical
> :value-length 20
> :stored-length 80
> :read-only nil
> :notify-handler FileNameNotify
> )
> (
> :type :button
> :name LoadButton
> wner ControlArea
> :x 10
> :y 85
> :constant-width nil
> :button-type :normal
> :width 51
> :height 19
> :foreground-color ""
> :label "LOAD"
> :label-type :string
> :menu nil
> :notify-handler LoadButtonNotify
> )
> (
> :type :text-field
> :name LoadAmountField
> wner ControlArea
> :x 70
> :y 85
> :width 96
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label ""
> :label-type :string
> :value-x 70
> :value-y 85
> :layout-type :horizontal
> :value-length 12
> :stored-length 80
> :read-only nil
> :notify-handler nil
> )
> (
> :type :message
> :name MagnificationHeader
> wner ControlArea
> :x 5
> :y 110
> :width 173
> :height 13
> :foreground-color ""
> :label "--Image Magnification--"
> :label-type :string
> )
> (
> :type :text-field
> :name ImageMagnificationField
> wner ControlArea
> :x 5
> :y 130
> :width 167
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "Scale:"
> :label-type :string
> :value-x 52
> :value-y 130
> :layout-type :horizontal
> :value-length 15
> :stored-length 80
> :read-only nil
> :notify-handler ImageMagnificationNotify
> )
> (
> :type :message
> :name ColorBoxHeader
> wner ControlArea
> :x 5
> :y 160
> :width 172
> :height 13
> :foreground-color ""
> :label "--Colour Box Selection--"
> :label-type :string
> )
> (
> :type :text-field
> :name RedLoField
> wner ControlArea
> :x 5
> :y 180
> :width 72
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "RLo:"
> :label-type :string
> :value-x 41
> :value-y 180
> :layout-type :horizontal
> :value-length 4
> :stored-length 10
> :read-only nil
> :notify-handler nil
> )
> (
> :type :text-field
> :name RedHiField
> wner ControlArea
> :x 100
> :y 180
> :width 71
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "RHI:"
> :label-type :string
> :value-x 135
> :value-y 180
> :layout-type :horizontal
> :value-length 4
> :stored-length 10
> :read-only nil
> :notify-handler nil
> )
> (
> :type :text-field
> :name GreenLoField
> wner ControlArea
> :x 5
> :y 200
> :width 72
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "GLo:"
> :label-type :string
> :value-x 41
> :value-y 200
> :layout-type :horizontal
> :value-length 4
> :stored-length 10
> :read-only nil
> :notify-handler nil
> )
> (
> :type :text-field
> :name GreenHiField
> wner ControlArea
> :x 100
> :y 200
> :width 71
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "GHi:"
> :label-type :string
> :value-x 135
> :value-y 200
> :layout-type :horizontal
> :value-length 4
> :stored-length 10
> :read-only nil
> :notify-handler nil
> )
> (
> :type :text-field
> :name BlueLoField
> wner ControlArea
> :x 4
> :y 220
> :width 72
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "BLo:"
> :label-type :string
> :value-x 40
> :value-y 220
> :layout-type :horizontal
> :value-length 4
> :stored-length 10
> :read-only nil
> :notify-handler nil
> )
> (
> :type :text-field
> :name BlueHiField
> wner ControlArea
> :x 100
> :y 220
> :width 71
> :height 15
> :foreground-color ""
> :text-type :alphanumeric
> :label "BHi:"
> :label-type :string
> :value-x 135
> :value-y 220
> :layout-type :horizontal
> :value-length 4
> :stored-length 10
> :read-only nil
> :notify-handler nil
> )
> (
> :type :button
> :name ColorboxApplyButton
> wner ControlArea
> :x 5
> :y 250
> :constant-width nil
> :button-type :normal
> :width 56
> :height 19
> :foreground-color ""
> :label "APPLY"
> :label-type :string
> :menu nil
> :notify-handler ColorApplyButtonNotify
> )
> (
> :type :button
> :name ColorResetButton
> wner ControlArea
> :x 100
> :y 250
> :constant-width nil
> :button-type :normal
> :width 55
> :height 19
> :foreground-color ""
> :label "RESET"
> :label-type :string
> :menu nil
> :notify-handler ColorResetButtonNotify
> )
> (
> :type :message
> :name ContourHeader
> wner ControlArea
> :x 5
> :y 290
> :width 174
> :height 13
> :foreground-color ""
> :label "---Contour Extraction---"
> :label-type :string
> )
> (
> :type :button
> :name QuitButton
> wner ControlArea
> :x 55
> :y 520
> :constant-width nil
> :button-type :normal
> :width 135
> :height 19
> :foreground-color ""
> :label "QUIT APPLICATION"
> :label-type :string
> :menu nil
> :notify-handler QuitButtonNotify
> )
> )
> ====== End of Description file ============
>
> Please help
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|