You are here:  » Generate XML File


Generate XML File

Submitted by dustin on Thu, 2006-11-16 14:43 in

David,

I am need of your help.

I want to take an XML file that is in a crazy format (that works fine on the Demo part of the site, but doesn't work in Visual Basic ADO.NET) and parse it in php, then save it out in a better format.

For some reason I can't get VB to read Attributes from the XML file or the nodes that have @ signs in them. So I figure since your script will read them I can open it up in here and create a new XML file for my VB app.

I don't need anything fancy with XSL or any or any kind of XML standards. This is just so I can get the data pasted to VB then a database then output to a powerpoint presentation - I have already got everything working except the fact that the XML file.

I just need the code that will allow me to create the new XML file and save it out. I think from all your other help I can get the loop to work to parse the exisiting XML data.

Thanks

Submitted by dustin on Thu, 2006-11-16 15:15

I actually found a good resource site and did a test and got it to generate a simple xml document (not using phpmagic yet, but just putting in sample text)

http://www.tonymarston.co.uk/php-mysql/dom.html

If you have anything you want too add please do so thanks.

Submitted by support on Thu, 2006-11-16 16:10

Hi dustin,

It's quite easy to make PHP output an XML document from each item that you have parsed in your record handler function. Have a look at the following thread:

http://www.magicparser.com/node/39

The script in that thread shouldn't require much modification. You can either stick with the RSS XML format as output or use your own tags, and then modify the code within the recordhandler function as required for the fields that are in your complex XML document...

Cheers!
David.

Submitted by dustin on Thu, 2006-11-16 17:13

That looks 100x easier. I got the other way to some what work but I was having a few issues so I'm going to go with your method.

Also do you know if I could make it so the user could have the option to save the XML file to their hard drive? or pass it to a Visual Basic application that will consume it?

Submitted by support on Fri, 2006-11-17 23:13

Hi,

You can force a download by changing the headers. Instead of:

  header("Content-Type: text/xml");

use:

  header("Content-Type: application/octet-stream");
  header("Content-Disposition: attachment; filename=filename.xml");

That will force the browser to display a download or open dialog box...

Cheers,
David.

Submitted by dustin on Sat, 2006-11-18 15:03

David,

Do I have to do anything special to allow the XML source file to be pulled from the local users hard drive?

I was doing a little test and when I try to get the file using c:\path to file it makes me a blank XML file. Before I was using an xml file that was on the net, but when this product is used the file will actual be on the local users machine.

 MagicParser_parse("file:\\\C:\Documents and Settings\townsend\Desktop\STRUCT VS FP.xml","myRecordHandler","xml|EXCHANGE/BATCHTEST/CLASHTESTS/CLASHTEST/CLASHRESULTS/CLASHRESULT/");

That is what I am trying now.

Submitted by dustin on Sat, 2006-11-18 15:09

I am planning to make it so the the file path is past to the script via the url.

ie:

file.php?xmlfile=c:\path\file.xml

The user is going to choose the file from Visual Basic then Visual Basic is going to pass the file via URL to the browser control and run the php code - pop up the save dialog - then the user will have the newly create XML file for the VB app to work.

This is definatly a long process for the end user, but it is better then the alternative of doing it manually or using the crap that the software gives us by default.

Submitted by support on Sun, 2006-11-19 12:31

Hello dustin,

Unfortunately that won't work because the file is local to the user - not your webserver.

To do this; you would have to implement a script which enabled your users to upload the file using HTML's file upload features. There's a good tutorial on the PHP website for handling file uploads:

http://uk2.php.net/features.file-upload

Having uploaded the file you can then open the uploaded copy and generate the re-formatted XML as required.

Hope this helps,
Cheers,
David.