1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Using separate file for global strings

Discussion in 'HTML & Website Design' started by rmkreeg, Oct 15, 2009.

  1. #1
    Is there a way to create a separate file that will store a list of strings that can be pulled by all the other web pages in a site?

    For instance, I would like to have a file of strings that list things like version info, webmaster name, email addresses, links, etc. and each string would be tied to an "alias" so that each web page references the alias when it needs to display the string. The use in this is that I could change the strings file and all the pages in a site would automatically be updated. I get a feeling that this is what XML is made for...but I just cant figure out how to integrate XML into my website as efficiently as this. I know theres a way, but I dont know it. Help please!


    As a psudo-example:


    ** in strings.xml **

    <SITE_INFO>
    <AUTHOR>John Smith</AUTHOR>
    <VERSION>v3.14</VERSION>
    <CONTACT>John.Smith@server.com</CONTACT>
    <MYSPACE>http://www.myspace.com/jsmith</MYSPACE>
    </SITE_INFO>


    ** in index.html **

    ...
    <head>
    // I know, this is blatent C code, dont flame. im looking for the html equivelent
    #include<strings.xml>
    </head>
    <body>
    <p>
    print(AUTHOR);
    </p>
    <p>
    print(VERSION);
    </p>
    <p>
    print(CONTACT);
    </p>
    <p>
    print(MYSPACE);
    </p>
    </body>
    ...


    ** output **

    John Smith
    v3.14
    John.Smith@server.com
    http://www.myspace.com/jsmith
     
    rmkreeg, Oct 15, 2009 IP
  2. rmkreeg

    rmkreeg Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    ...programmers law #1,345: Look all you want, you won't find the answer to what your looking for until directly after asking someone for help. Only then will the answer pop up and make you look like a dork for even asking in the first place.

    I'll have to thank w3schools for this bit of code...

    <html>
    <body>
    
    <script type="text/javascript">
    if (window.XMLHttpRequest)
      {
      xhttp=new window.XMLHttpRequest();
      }
    else // Internet Explorer 5/6
      {
      xhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xhttp.open("GET","cd_catalog.xml",false);
    xhttp.send("");
    xmlDoc=xhttp.responseXML; 
    
    document.write("<table border='1'>");
    var x=xmlDoc.getElementsByTagName("CD");
    for (i=0;i<x.length;i++)
      { 
      document.write("<tr><td>");
      document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
      document.write("</td><td>");
      document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
      document.write("</td></tr>");
      }
    document.write("</table>");
    </script>
    
    </body>
    </html>
    Code (markup):
     
    rmkreeg, Oct 15, 2009 IP