PDA

View Full Version : Question on XML files


ABC123

crimmelcp
09-26-2009, 06:07 PM
I need to copy a XML file to a text file and keep the xml structure.

I can do it manually by opening the xml file,selecting the info, copy, and then open notepad and paste.

I need to do it from a script.
If I use filecopy2 it loses the formatting and puts everything in 1 line.

the XML structure is something like this:
<?xml version="1.0" encoding="utf-8" ?>
- <legend>
- <categories>
- <category>
<id>all</id>
- <title>
- <![CDATA[ Categories
]]>
</title>
- <alt>
- <![CDATA[ Select,Deselect,<br><b>all</b> categories
]]>
</alt>
<style>headingText</style>
<textColor>0x000000</textColor>
</category>
- <category>
<id>none</id>
- <title>
- <![CDATA[ None
]]>
</title>
<bgColor>0xc1c8d9</bgColor>
<textColor>0x000000</textColor>
</category>

if I use file copy it changes the structure to(all one line)
<?xml version='1.0' encoding='UTF-8' standalone='no'?><events><event><event_id>0</event_id><title>2nd Interview with State</title><date

Any Ideas
Thanks
Charlie Crimmel

NoeticCC
09-26-2009, 06:17 PM
As far as I am aware the XML should work the same only the tags matter...

Is it possible you are copying to a UNIX file system where line breaks are different from DOS/Windows ones?

Anyway maybe stritran(xmltext,"><",crlf()) or stritran(xmltext,"><",chr(13)) would do the trick? [chr(13) being the UNIX return character]

Stan Mathews
09-26-2009, 08:00 PM
I can do it manually by opening the xml file,selecting the info, copy, and then open notepad and paste.The xbasic equivalent would be


Data = FILE.TO_STRING( "somefilename.xml" )
FILE.FROM_STRING( "somefilename.txt", Data )

crimmelcp
09-26-2009, 08:14 PM
Stan:
it still put all tags on one continous line

I need each tag on its own line

<?xml version='1.0' encoding='UTF-8' standalone='no'?><events><event><event_id>0</event_id><title>2nd Interview with State</title><date>09/02/2009</date><time>14:00</ti

mmaisterrena
09-26-2009, 08:32 PM
Come on!! just buy Alpha Calendar
Or at least buy Flash calendar from the link on my page (I get a little comision that way);)

crimmelcp
09-26-2009, 08:59 PM
Muricio:
I will buy Alpha Calendar, but I cannot get the grids to update the calendar and events and the categories and locations.

I have not figured out how to add the link so when I double click on the day it will bring up my a5w page.

I am waiting on your video.

I have flash calendar. But it is not integrated into Alpha.

Thanks
Charlie Crimmel

mmaisterrena
09-26-2009, 09:23 PM
Thank you Charlie I posted the answer here

http://msgboard.alphasoftware.com/alphaforum/showthread.php?p=509230#post509230

Lance Gurd
09-27-2009, 02:44 AM
Charlie,

Using the help here (http://support.alphasoftware.com/WhatsNewInV9/generated_NewInA5V9_XMLParser.htm#Parsing%20XML%20Documents%20with%20Xbasic) I have managed to play around with XML with relative ease. For instance this
dim sm as p
dim xml as c
sm=xmlschemamanager.get()
xml=get_from_file("C:\Documents and Settings\lance\events.xml")
'
dom=sm.loadXML(xml)
opens the events XML file I can then use
dom.top.outerXML to see the whole file with tags on separate lines. There are then lots of ways of addressing the different elements at your disposal.

Tim Kiebert
09-27-2009, 08:33 AM
Stan:
it still put all tags on one continous line

I need each tag on its own line

<?xml version='1.0' encoding='UTF-8' standalone='no'?><events><event><event_id>0</event_id><title>2nd Interview with State</title><date>09/02/2009</date><time>14:00</ti

Try this function. I made it to handle specific files I was getting from a web service.
As Andrea said the xml should still function as intended even if on one line.
I used the function just so I could examine the xml received while testing. Much easier to read when not on one line.

Stan Mathews
09-28-2009, 09:31 AM
I need to copy a XML file to a text file and keep the xml structure.
Do you really?

If you want to operate on an xml file with Alpha's file methods you don't need to do that. Just open the xml file itself.


fil = file.open("C:\tempdb\cxml\Copy of ccxml.xml",FILE_RW_EXCLUSIVE)
ln = fil.read_line()
? ln
= <?xml version="1.0" encoding="utf-8"?>
ln = fil.read_line()
? ln
= "<legend>"
ln = fil.read_line()
? ln
= " <categories>"
ln = fil.read_line()
? ln
= " <category>"
ln = fil.read_line()
? ln
= " <id>all</id>"