Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Text file to XML


  • Please log in to reply

#1
ali.B

ali.B

    Trusted Helper

  • Malware Removal
  • 3,086 posts
suppose i have a text file with this format

33.87816 35.50008
33.86892 35.52231
33.82589 35.42240

I want to convert it into XML into this form

<markers>
 <marker lat="33.87816" lng="35.50008" label="Car 1"/>
 <marker lat="33.86892" lng="35.52231" label="Car 2"/>
 <marker lat="33.82589" lng="35.42240" label="Car 3"/>
</markers>


I have been trying with stylus studio so far, any another suggestion ?
  • 0

Advertisements


#2
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Although not an automated solution, you can do this pretty easily with Excel. Just import the data and perform a Text to Columns conversion. This should give you two columns of data. Assuming they start at the first row and are columns A and B, set the C column to the following formula:
="<marker lat="""&A1&""" lng="""&B1&""" label=""Car "&ROW()&"""/>"

Autofill the formula down for all the rows. This will give you the marker elements, which you can just copy out into a text file, surround with the <markers /> element, and save as .xml.

It would be even easier if the file was a CSV, you could then just open it up in Excel and do the formula conversion. If you don't have Excel, you can use OpenOffice or even Google Apps to perform the formula conversion.

Let me know if any of the above does not make sense.

Regards,

Ax
  • 0

#3
ali.B

ali.B

    Trusted Helper

  • Topic Starter
  • Malware Removal
  • 3,086 posts
all make sense but is it possible to save this as a .xml file ? and only the row c ;)

i was thinking more toward a c++ program as i have worked before with c++, what do you think ?
  • 0

#4
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts

all make sense but is it possible to save this as a .xml file ? and only the row c ;)

You'd have to copy it out of Excel to save it as xml.

i was thinking more toward a c++ program as i have worked before with c++, what do you think ?

That would work too, just read the text file in, create the output xml file, loop through the lines, add your <marker> elements to the output file with fprintf, and wrap it in the parent <markers> node. As long as your text file is a flat file, you should have no problems producing simple xml with a script.

C++ isn't my forte, but if you need assistance, I can help you out.

Regards,

Ax
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP