Skip to main content
BurtleEd
Known Participant
February 16, 2010
Question

Load information from an external xml file

  • February 16, 2010
  • 3 replies
  • 2644 views

I have a web page that has titles, and links, that show location on a google map. I am trying to create an external file that an average user can use to quickly change the values on the page. For example instead of the page title saying "Weather for Bossier City, LA" with a url www.bossierweather.net the user could modify an XML file and then the page title would change to "Weather for Dallas, TX". and modify the URL to www.dallasweather.new  I am kind of new to Coldfusion but I am sure its possible.

    This topic has been closed for replies.

    3 replies

    Inspiring
    February 18, 2010

    Who exactly is your target audience if you expect them to edit xml files?

    BurtleEd
    BurtleEdAuthor
    Known Participant
    February 22, 2010

    I got it working and it works great!!!

    I do have one other question.

    I have some locations represented on a google map as a layer. The locations come from an XML file and it works really well. I wanted to see if there was a way that when a user clicks on one of the set locations on the map then some information in a table on the page would also change all comming from my XML file.

    Below is my code.

    <!--- Read source xml file, assume both files within same folder --->
    <cfset MyXmlFile = ExpandPath("../sourceInfo.xml") />
    <cffile action="read" file="#MyXmlFile#" variable="input_xml" />
    <!--- Parse the file --->
    <cfset input_xml = #xmlParse(input_xml)# />
    <cfset pageTitle = "#input_xml.externalInfo.pageTitle.xmlText#" />
    <!--- Set titles and links to the information given on the source xml file --->
    <cfset map1Title = "#input_xml.externalInfo.map1Title.xmlText#" />
    <cfset mapCenterlat = "#input_xml.externalInfo.mapCenterlat.xmlText#" />
    <cfset mapCenterlong = "#input_xml.externalInfo.mapCenterlong.xmlText#" />
    <cfset mapCenterSize = "#input_xml.externalInfo.mapCenterSize.xmlText#" />
    <cfset mapType = "#input_xml.externalInfo.mapType.xmlText#" />

    <cfset mapLatA = "#input_xml.externalInfo.mapLatA.xmlText#" />
    <cfset mapLonA = "#input_xml.externalInfo.mapLonA.xmlText#" />


    <cfset mapLocationsA = "#input_xml.externalInfo.mapLocationsA.xmlText#" />
    <cfset mapPhoneA = "#input_xml.externalInfo.mapPhoneA.xmlText#" />
    <cfset mapICAOA = "#input_xml.externalInfo.mapICAOA.xmlText#" />
    <cfset mapIWWCA = "#input_xml.externalInfo.mapIWWCA.xmlText#" />

    Here is the google stuff

    <title><cfoutput>#map1Title#</cfoutput></title>
        <script src="http://maps.google.com/maps?file=api&v=2&amp;"
                type="text/javascript"></script>
        <script type="text/javascript">
        function initialize() {
        
       if (GBrowserIsCompatible()) {
     
      var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(<cfoutput>#mapCenterlat#</cfoutput>,<cfoutput>#mapCenterlong#</cfoutput>), <cfoutput>#mapCenterSize#</cfoutput>);
      map.setMapType(<cfoutput>#mapType#</cfoutput>);
      map.setUIToDefault();

            // Create a base icon for all of our markers that specifies the
            // shadow, icon dimensions, etc.
            var baseIcon = new GIcon(G_DEFAULT_ICON);
            baseIcon.shadow = "http://www.google.com/mapfiles/shadow51.png";
            baseIcon.iconSize = new GSize(20, 34);
            baseIcon.shadowSize = new GSize(37, 34);
            baseIcon.iconAnchor = new GPoint(9, 34);
            baseIcon.infoWindowAnchor = new GPoint(9, 2);

            // Creates a marker whose info window displays the letter corresponding
            // to the given index.
            function createMarker(point, title, contact, icao, iwwc, letter) {
              // Create a lettered icon for this point using our icon class
              var letteredIcon = new GIcon(baseIcon);
              letteredIcon.image = "http://www.google.com/mapfiles/marker"+letter+".png";

              // Set up our GMarkerOptions object
              markerOptions = { icon:letteredIcon, title:title };
              var marker = new GMarker(point, markerOptions);

              GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml("<u><b>" + title + "</b></u><br /><b>Phone:&nbsp</b>" + contact + "<br /><b>ICAO:&nbsp</b>" + icao + "&nbsp&nbsp&nbsp&nbsp&nbsp<B>IWWC:&nbsp</b>"+iwwc);
              });
              return marker;
            }


      /** ADD OVERLAYS **/
            map.addOverlay(createMarker(new GLatLng(<cfoutput>#mapLatA#</cfoutput>,<cfoutput>#mapLonA#</cfoutput>), "<cfoutput>#mapLocationsA#</cfoutput>", "<cfoutput>#mapPhoneA#</cfoutput>", "<cfoutput>#mapICAOA#</cfoutput>", "<cfoutput>#mapIWWCA#</cfoutput>", "A"));

    What I am needing if possible.

    I have some things about the map location above that I need to display on a table when a user clicks on the map location. Is this possible?

    Inspiring
    February 23, 2010
    Inspiring
    February 17, 2010

    In your source file (sourceInfo.xml, let’s say), you need something like this:

    < <?xml version="1.0" encoding="utf-8" ?>

    <externalInfo>

       <taboneTitle>Overview</taboneTitle>

       <tabtwoTitle>Documents</tabtwoTitle>

       <tabthreeTitle>Heads Up Display</tabthreeTitle>

       <iframe1Src>Area 1\description.html</iframe1Src>

       <iframe2Src>../../Documents/docs.htm</iframe2Src>

       <iframe3Src>https://ows.scott.af.gov/</iframe3Src>

       <iframe4Src>Area 1\Roundup.htm</iframe4Src>

    <  </externalInfo>

    Then on the main page we shall read the xml file, parse it and use the xml details as our titles and links as below:

    <!--- Read source xml file, assume both files within same folder --->

    <cfset MyXmlFile = ExpandPath("sourceInfo.xml") />

    <cffile action="read" file="#MyXmlFile#" variable="input_xml" />

    <!--- Parse the file --->

    <cfset input_xml = #xmlParse(input_xml)# />

    <!--- Set titles and links to the information given on the source xml file --->

    <cfset taboneTitle = "#input_xml.externalInfo.taboneTitle.xmlText#" />

    <cfset tabtwoTitle = "#input_xml.externalInfo.tabtwoTitle.xmlText#" />

    <cfset tabthreeTitle = "#input_xml.externalInfo.tabthreeTitle.xmlText#" />

    <cfset iframe1Src = "#input_xml.externalInfo.iframe1Src.xmlText#" />

    <cfset iframe2Src = "#input_xml.externalInfo.iframe2Src.xmlText#" />

    <cfset iframe3Src = "#input_xml.externalInfo.iframe3Src.xmlText#" />

    <cfset iframe4Src = "#input_xml.externalInfo.iframe4Src.xmlText#" />

    <div id='demo' class='yui-navset' style="display: inline;">

    <ul class='yui-nav'>

      <li class='selected' id='tabOneLabel'><a href='#tabone'><em><cfoutput>#taboneTitle#</cfoutput></em></a></li>

      <li id='tabTwoLabel'><a href='#tabtwo'><em><cfoutput>#tabtwoTitle#</cfoutput></em></a></li>

      <li id='tabThreeLabel'><a href='#tabthree'><em><cfoutput>#tabthreeTitle#</cfoutput></em></a></li>

      <li id='tabFourLabel'><a href='#tabfour'><em>Metwatch</em></a></li>

      <li id='tabFiveLabel'><a href='#tabfive'><em>Regl Radar / Lightning</em></a></li>

      <li id='tabSixLabel'><a href='#tabsix'><em>Regl Satellite</em></a></li>

      <li id='tabSevenLabel'><a href='#tabseven'><em>CT/RI Radar</em></a></li>

      <li id='tabEightLabel'><a href='#tabeight'><em>MA/RI Radar</em></a></li>

      <li id='tabNineLabel'><a href='#tabnine'><em>VAD Wind Profile</em></a></li>

      <li id='tabTenLabel'><a href='#tabten'><em>CT Skew-T/MOS</em></a></li>

      <li id='tabElevenLabel'><a href='#tabeleven'><em>MA Skew-T/MOS</em></a></li>

    </ul>

    <div class='yui-content'>

      <div id='tabone'>

       <IFRAME SRC="<cfoutput>#iframe1Src#</cfoutput>" WIDTH=99% HEIGHT=90% ALIGN=center></IFRAME>

      </div>

      <div id='tabtwo''>

       <IFRAME SRC="<cfoutput>#iframe2Src#</cfoutput>" WIDTH=99% HEIGHT=90% ALIGN=center></IFRAME>

      </div>

      <div id='tabthree''>

       <IFRAME SRC="<cfoutput>#iframe3Src#</cfoutput>" WIDTH=99% HEIGHT=98% ALIGN=center></IFRAME>

      </div>

      <div id='tabfour'>

       <IFRAME SRC="<cfoutput>#iframe4Src#</cfoutput>" WIDTH=99% HEIGHT=95% ALIGN=center></IFRAME>

      </div>

      <div id='tabfive'>

       <IFRAME SRC="Area 1\Radar-Lightning.html"  WIDTH=99% HEIGHT=95% ALIGN=center></IFRAME>

      </div>

      </div>

    </div>

    BurtleEd
    BurtleEdAuthor
    Known Participant
    February 17, 2010

    Man it seemed to be working great until I started getting the error below, any thoughts?

    The content of elements must consist of well-formed character data or markup.
    The error occurred in C:\wwwroot\Layout\FrontPage\15OWS\Area1.cfm: line 14
    12 : <!--- Parse the file --->
    13 : 
    14 : <cfset input_xml = #xmlParse(input_xml)# />
    15 : 
    16 : 
    

    Inspiring
    February 18, 2010

    Please validate your xml file to ensure it is well formed. You can use W3C XML validator:

    http://w3schools.com/xml/xml_validator.asp

    Inspiring
    February 16, 2010

    For clarity, could we have a look at part of the code?

    BurtleEd
    BurtleEdAuthor
    Known Participant
    February 16, 2010

    I bolded and made the items that need to be changed from an external file. Hope this makes sense

    <!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

    <html>

    <!-- optional skin for border tabs -->
    <link rel='stylesheet' type='text/css' href='http://yui.yahooapis.com/2.2.2/build/tabview/assets/border_tabs.css'>

    <style type='text/css'>
    #demo { width:1260px; }
    #demo .yui-content { padding:3px; } /* pad content container */
    #demo img { margin-right:3px; }
    #tabone, #tabtwo, #tabthree, #tabfour, #tabfive, #tabsix, #tabseven, #tabeight, #tabnine, #tabten, #tabeleven, #tabtwelve, #tabthirteen { height:910px; }
    </style>


    <div id='demo' class='yui-navset'>
    <ul class='yui-nav'>
      <li class='selected' id='tabOneLabel'><a href='#tabone'><em>Overview</em></a></li>
      <li id='tabTwoLabel'><a href='#tabtwo'><em>Documents</em></a></li>
      <li id='tabThreeLabel'><a href='#tabthree'><em>Heads Up Display</em></a></li>
      <li id='tabFourLabel'><a href='#tabfour'><em>Metwatch</em></a></li>
      <li id='tabFiveLabel'><a href='#tabfive'><em>Regl Radar / Lightning</em></a></li>
      <li id='tabSixLabel'><a href='#tabsix'><em>Regl Satellite</em></a></li>
      <li id='tabSevenLabel'><a href='#tabseven'><em>CT/RI Radar</em></a></li>
      <li id='tabEightLabel'><a href='#tabeight'><em>MA/RI Radar</em></a></li>
      <li id='tabNineLabel'><a href='#tabnine'><em>VAD Wind Profile</em></a></li>
      <li id='tabTenLabel'><a href='#tabten'><em>CT Skew-T/MOS</em></a></li>
      <li id='tabElevenLabel'><a href='#tabeleven'><em>MA Skew-T/MOS</em></a></li>

    </ul>
    <div class='yui-content'>
      <div id='tabone'>
       <IFRAME SRC="Area 1\description.html" WIDTH=99% HEIGHT=90% ALIGN=center></IFRAME>
      </div>

      <div id='tabtwo''>
       <IFRAME SRC="../../Documents/docs.htm" WIDTH=99% HEIGHT=90% ALIGN=center></IFRAME>
      </div>

      <div id='tabthree''>
       <IFRAME SRC="https://ows.scott.af.gov/" WIDTH=99% HEIGHT=98% ALIGN=center></IFRAME>
      </div>

      <div id='tabfour'>
       <IFRAME SRC="Area 1\Roundup.htm" WIDTH=99% HEIGHT=95% ALIGN=center></IFRAME>
      </div>

      <div id='tabfive'>
       <IFRAME SRC="Area 1\Radar-Lightning.html"  WIDTH=99% HEIGHT=95% ALIGN=center></IFRAME>
      </div>

      </div>
    </div>