0

Sorry, about this. I have been searching for a work around for this for a few hours now

(self taught HTML CSS etc)

I have build a web page designed to act as a shop for people to book excursions that i run.

I would like to create XML files that will connect with HTML pages so that they can populate data into the page (to save me from editing the HTML everytime.

I can find examples for photos but nothing for text (the info should not be displayed in a table)

here is what I have so far. I have copied this from a web tutorial, I got it doing what I wanted within the W3 schools 'app' but have applied it to this. I am unsure as to what the 0's mean in the script part.

THANKS AGAIN

    SCRIPT

    <script type="text/xml" src="checking.xml">
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.open("GET","checking.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;

    document.getElementById("TRIPINFO").innerHTML=
    xmlDoc.getElementsByTagName("DATE")[0].childNodes[0].nodeValue;
    document.getElementById("TRIPINFO").innerHTML=
    xmlDoc.getElementsByTagName("DESTINATION")[0].childNodes[0].nodeValue;
    document.getElementById("TRIPINFO").innerHTML=
    xmlDoc.getElementsByTagName("DESC")[0].childNodes[0].nodeValue;
    document.getElementById("TRIPINFO").innerHTML=
    xmlDoc.getElementsByTagName("PRICE")[0].childNodes[0].nodeValue;


    </script>

    HTML

    <p class="destpictext">
<span style="background-color:#2f2fae" id="DATE"> </span> <br />
<span style="background-color:#2f2fae"id="DESTINATION"> </span> <br />
<span style="background-color:#2f2fae" id="DESC"> </span> <br />
<span style="background-color:#2f2fae" id="PRICE"> </span> </p>
    </div>
5
  • look at jQuery ajax Commented Nov 21, 2013 at 3:30
  • 1
    You forgot the "what I have so far" part. I can't tell if you're looking to use xml files as templates or as data source. You don't need to create html every time if you implement template engine server side Commented Nov 21, 2013 at 3:34
  • coding.smashingmagazine.com/2012/12/05/client-side-templating Commented Nov 21, 2013 at 3:40
  • learning a little bit of php and using a database instead of an xml file will be worth it in the long run imo. Commented Nov 21, 2013 at 3:42
  • The getElementById function returns an array and [0] means that it will take the first element in that array. Does the code work or do you get some errors? What about the xml file? Is it placed in the same folder as the html file? Commented Nov 21, 2013 at 3:57

1 Answer 1

1

You cannot insert directly XML into a webpage. XML isn't used that much in web dev. It's best to use a Server Side Scripting language like PHP and a Database to get the items for the shop. However if you really want to insert xml into a webpage, there are two good ways to do it:

  1. With javascript: http://api.jquery.com/jQuery.ajax/ (to load), http://api.jquery.com/jQuery.parseXML/ (to parse)

  2. With php: http://php.net/manual/en/book.xml.php

I would use php.

Sign up to request clarification or add additional context in comments.

4 Comments

There is always xslt!
@user3015838 are you doing that on purpose to emphasize that you have no code at all? This is second time you haven't provided code.
@Anthony No. It's truncated when you try to paste too much code, it's too large and therefore it needs to go into the body of the question or into a pastebin.
Sorry I hit the enter button on the comment. apols, question edited with code example!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.