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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omar999
    New Member
    • Mar 2010
    • 120

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

    hi guys

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

    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <promos>
      <flight type="OW">
      <url></url>
        <departure>Gatwick</departure>
        <destination>TORONTO</destination>
        <departuredate year="2010" month="5" day="27, 28"/>
        <price>139</price>
        <currencycode>£</currencycode>
      </flight>
      <flight type="OW">
      <url></url>
        <departure>Gatwick</departure>
        <destination>Vancouver</destination>
        <departuredate year="2010" month="5" day="7, 8, 9"/>
        <price>149</price>
        <currencycode>£</currencycode>
      </flight>
    </promos>
    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
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you can insert ASP code, but you have to do it in a processing instruction node or CDATA node (ref.)

    Comment

    • omar999
      New Member
      • Mar 2010
      • 120

      #3
      thanks for the quick reply - so in my case rather than
      Code:
      <price>139</price>
      instead wrap it within cdata node?
      Code:
      <price><![CDATA[ ASP CODE HERE ]]></price>
      ?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        that depends on how you want to handle the code.

        Comment

        • omar999
          New Member
          • Mar 2010
          • 120

          #5
          im not with you - can you please elaborate...

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            what is the purpose of the ASP code?

            Comment

            • omar999
              New Member
              • Mar 2010
              • 120

              #7
              to connect to sql db and retrieve data - i.e in this case an integer to go inbetween the price xml tag..

              regards
              Omar.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                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
                Code:
                <?php
                // file: price.php
                    header("Content-Type: text/xml");
                    echo '<?xml version="1.0" ?>';
                    include "functions.inc";
                    $price = getPriceFromDB();
                ?>
                <price><?php echo $price; ?></price>

                Comment

                • omar999
                  New Member
                  • Mar 2010
                  • 120

                  #9
                  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

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    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.

                    Comment

                    • omar999
                      New Member
                      • Mar 2010
                      • 120

                      #11
                      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

                      Code:
                      <price><![CDATA[<!--#include virtual="price.asp" -->]]></price>
                      would that work?

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        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.

                        Comment

                        • omar999
                          New Member
                          • Mar 2010
                          • 120

                          #13
                          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.

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            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)

                            Comment

                            • omar999
                              New Member
                              • Mar 2010
                              • 120

                              #15
                              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'...

                              Comment

                              Working...