473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

asp / sql code in xml file possible? or other options to retrieve recordset in xml

120 100+
hi guys

im fairly new to xml so bear with me if this is a newbie question. I have an xml file

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <promos>
  3.   <flight type="OW">
  4.   <url></url>
  5.     <departure>Gatwick</departure>
  6.     <destination>TORONTO</destination>
  7.     <departuredate year="2010" month="5" day="27, 28"/>
  8.     <price>139</price>
  9.     <currencycode>£</currencycode>
  10.   </flight>
  11.   <flight type="OW">
  12.   <url></url>
  13.     <departure>Gatwick</departure>
  14.     <destination>Vancouver</destination>
  15.     <departuredate year="2010" month="5" day="7, 8, 9"/>
  16.     <price>149</price>
  17.     <currencycode>£</currencycode>
  18.   </flight>
  19. </promos>
  20.  
and I'd like to retrieve the price from our sql database - but when I try to insert asp code in to this xml file it errors.. is it not possible to insert asp code within an xml file?

can you insert xml code in an asp file as an alternative? or is there a way to insert an asp file in to an xml file as an include??

please advise
thanks
Apr 27 '10 #1
18 1976
Dormilich
8,658 Expert Mod 8TB
you can insert ASP code, but you have to do it in a processing instruction node or CDATA node (ref.)
Apr 27 '10 #2
omar999
120 100+
thanks for the quick reply - so in my case rather than
Expand|Select|Wrap|Line Numbers
  1. <price>139</price>
  2.  
instead wrap it within cdata node?
Expand|Select|Wrap|Line Numbers
  1. <price><![CDATA[ ASP CODE HERE ]]></price>
  2.  
?
Apr 27 '10 #3
Dormilich
8,658 Expert Mod 8TB
that depends on how you want to handle the code.
Apr 27 '10 #4
omar999
120 100+
im not with you - can you please elaborate...
Apr 27 '10 #5
Dormilich
8,658 Expert Mod 8TB
what is the purpose of the ASP code?
Apr 27 '10 #6
omar999
120 100+
to connect to sql db and retrieve data - i.e in this case an integer to go inbetween the price xml tag..

regards
Omar.
Apr 27 '10 #7
Dormilich
8,658 Expert Mod 8TB
so you want to execute the ASP before loading/reading/whatever the XML?

then write an ASP page, that returns the ready made XML file.

you’d need the processing instruction, if you’d execute the ASP afterwards.

example in PHP, since I don’t know ASP
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // file: price.php
  3.     header("Content-Type: text/xml");
  4.     echo '<?xml version="1.0" ?>';
  5.     include "functions.inc";
  6.     $price = getPriceFromDB();
  7. ?>
  8. <price><?php echo $price; ?></price>
Apr 27 '10 #8
omar999
120 100+
I don't want to create another asp page as I'm trying to maintain as few pages as possible.

Ideally I just want to use an xml page and retrieve a value [in my case a price] using asp from a sql database.

can anyone else advise of any solutions please?

thanks in advance
Apr 27 '10 #9
Dormilich
8,658 Expert Mod 8TB
I don't want to create another asp page as I'm trying to maintain as few pages as possible.
and how do you tell the ASP interpreter to execute the code?

Ideally I just want to use an xml page and retrieve a value [in my case a price] using asp from a sql database.
XML doesn’t do that.
Apr 27 '10 #10
omar999
120 100+
okay - alternatively if I created another asp file to retrieve a value from sql db and then pull in this asp file within the xml as an include? so something like this

Expand|Select|Wrap|Line Numbers
  1. <price><![CDATA[<!--#include virtual="price.asp" -->]]></price>
  2.  
would that work?
Apr 27 '10 #11
Dormilich
8,658 Expert Mod 8TB
a) you don’t need CDATA tags
b) if you tell the ASP interpreter to parse the XML file
… maybe, you have to ask someone knowledgeable in ASP for the exact procedure.
Apr 27 '10 #12
omar999
120 100+
correct me if im wrong but are you trying to say to use an asp file instead of an xml file and then output/convert the asp to xml?

I have to use an xml file as we are sending this xml file to a 3rd party company so they are expecting an xml file.

I will ask in the asp section for some advise - if you have any other ideas please do let me know.

be well

Omar.
Apr 27 '10 #13
Dormilich
8,658 Expert Mod 8TB
I have to use an xml file as we are sending this xml file to a 3rd party company so they are expecting an xml file.
that depends on how you deliver. if they just access the file over the net (i.e. only reading) that doesn’t matter, because you give them an XML file (MIME type overrides file extension).
if you send the file (e.g. via email), you have to dump the result into a file (which may bear any name or file extension you like)
Apr 27 '10 #14
omar999
120 100+
we do not send them the file via email thats for sure - they appear to read it as they have ftp access to our files etc but I will find out for 100% sure on details.

im not sure what you mean by 'dump the result into a file'...
Apr 27 '10 #15
Dormilich
8,658 Expert Mod 8TB
im not sure what you mean by 'dump the result into a file'...
I mean: "save as …"

so it appears that you have to save the result XML code to a file, since the 3rd party does not/cannot make use of the ASP interpreter. (you have to write a script, that generates the XML file)
Apr 27 '10 #16
JamieHowarth0
533 Expert 512MB
OK, so you need to generate an XML file from database data, which is then accessed via FTP via a third-party.

You'd generate the XML file as a string in ASP, then save it as an XML file to disk.
In pseudo-code:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'Connect to DB
  3. String myXml = "<price>{0}</price>"
  4. 'dr is your recordset with the data pulled from your DB
  5. String myXml = Replace(myXml, "{0}", dr("Price"))
  6. Dim fso = CreateObject("Scripting.FileSystemObject")
  7. Set fs = fso.CreateTextFile("myXmlFile.xml") 
  8. fs.WriteLine(myXml) 
  9. fs.Close
  10. Set fs = Nothing
  11. %>
  12.  
Hope this helps.

codegecko
Apr 27 '10 #17
Monomachus
127 Expert 100+
@omar999
Excuse me, but this is not a great idea. Why don't you try to work with XML from ASP and not inverse? I mean usually you'd have some data you need to insert into XML but this isn't too complex. I mean putting an ASP into XML just to take one value from database... is too strange and isn't really professional. I mean look at alternatives really. Perhaps the most correct thing to have a method that will do that for you and you just insert this value into xml.
Apr 27 '10 #18
omar999
120 100+
codegecko - thanks for your reply. I've read your post several times and although I may not fully understand but I think this may be the way forward to generate the xml and then save the file on our server.

Monomachus - im trying to eradicate the need to manually enter in any data in to the xml file while it can just retrieve this data directly from our db. hence i want to automate this process. i need to retrieve aprox 4 values from sql db in to this xml file - and there's about 8 xml files so in the long run it will be worthwhile.
Apr 27 '10 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kingdom | last post by:
I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car' and the second box will list all the car...
2
by: Sunshine | last post by:
My original thought was to save the recordset into a text file. However, because of permissions I am unable to do this and will not be able to change the permissions. My next thought was to open...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
11
by: Shawn Milo | last post by:
I put this together yesterday, and I thought I'd share it. It works in both IE and Mozilla Firefox. I posted something similar to this months back, but it was much longer, and only worked in IE....
4
by: pamelafluente | last post by:
I am trying to pass a javascript variable to ASP. It almost works, except for the postback part. Infact if one clicks on the div and on the button it can be seen that the variable passes...
3
by: jpr | last post by:
Hello, I have a form on which I have a cmdbutton to copy a couple of fields into another table (MASTER) using the SSN on the active form as criteria. In the active form (based on a tables...
4
by: Kosmos | last post by:
Hey guys...as a relatively new programmer, I try to give back where I can. Below is the code for a useful program I believe many of you could use...just don't use the same exact code because...well I...
5
by: Eric Layman | last post by:
Hi, Many years ago when I first learnt abt web dev in school, I was taught this methodology: <html> blah blabh
1
by: rn5a | last post by:
I want an ASP app to retrieve records from a MS-Access database table but display them in a HTML table but I want the HTML table table to display only 7 records in a row (<tr>...</tr>) in 7...
1
by: Subrato | last post by:
Hi, I am very new to xml and I have this piece of code which I took off a website. The situation is that on of the website, user files up a form and it is submitted. On submission, the page should...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.