1

How can I read a XML file on HTML webpage?

I just know very basic JavaScript. I am trying to change value in footer of my website using XML because I have more than 100 pages and every time I change something in the footer, I have to change all 100 pages manually. That's why I want to change the footer links through XML.

I want my XML link value to go in anchor tags href attribute:

<a href="here goes the url using xml">

Also, the name of the website between the anchor tags too:

<a href="here goes link value ">here goes the name of the url using xml</a>

My HTML page should look like this:

<a href "here goes the url">here goes the name of the url using xml</a>
arttronics
  • 9,957
  • 2
  • 26
  • 62
Bloomberg
  • 2,317
  • 2
  • 25
  • 47
  • Remember to accept the answer (click the check near the upvote/downvote buttons) of the answer that helped you... –  Dec 29 '12 at 18:35

5 Answers5

1

If you just want to change the footer and that is being used in 100 pages, You can do this. Make a footer html page and include it in every page. This way if you need to make any changes in the footer, you will need to do it in 1 single place. In jsp you have to write

<jsp:include page="PageFooter.jsp" />

This solution might help too How to include an HTML page into another HTML page without frame/iframe?

Community
  • 1
  • 1
Abhishek kumar
  • 2,586
  • 5
  • 32
  • 38
1

Ah yes. Does your server have PHP enabled? (Most have it enabled by default.) JavaScript AJAX could do this, but PHP would be a much better solution.

Just paste this in your site:

<a href="<?php include 'file.xml'; ?>">here goes the name of the url using xml</a>

Change "file.xml" to whatever file the URL will be saved at. You could also use .txt or even .php or .html. And whenever there would be a change to URL in the file.xml, it would be reflected in all your pages.

Edit: Instead of referring to every link in your footer, why don't you just make one footer which you include, like this:

<?php include 'footer.html'; ?>

And inside "footer.html" would be your footer. Whenever you'd change footer.html, it would also be changed in every page using as the footer.

Tell me if this helps. :)

Edit: Actually doing this in Ajax isn't all that hard. :) Check out the load function in jQuery (a JavaScript library):

$('#result').load('ajax/test.html');
0

I hope this will help you without javascript.

xml file

<table>   <column>
    <column_id>1</news_id>
    <column_heading>heading</column_heading>    <column_details>details</column_details>    <column_url>url link</column_url>      </column> </table>

.aspx file

 <asp:Repeater runat="server" ID="XMLRepeater">
                    <ItemTemplate> <a  href="<%#Page.ResolveUrl(DataBinder.Eval(Container.DataItem, "column_url").ToString())%>"  target="_blank">                                    
                         <span >   <%# DataBinder.Eval(Container.DataItem, "column_heading") %>
                                    </span></a>
</ItemTemplate>
                </asp:Repeater>

aspx.cs file

protected void BindXMLToRepeater()
    {
        XmlTextReader xmlreader = new XmlTextReader(Server.MapPath("filename.xml"));
        try
        {

            DataSet ds = new DataSet();
            ds.ReadXml(xmlreader);
            //xmlreader.Close();

            DataTable dt = new DataTable();
            dt = (DataTable)ds.Tables[0];               

            //create dynamic data table
            DataTable dynamicTable = new DataTable();

            //DataRow
            DataRow dynamicRow;
            //DataColumn for Name and Time
            DataColumn id = new DataColumn("column_id", typeof(string));
            DataColumn heading = new DataColumn("column_heading", typeof(string));
            DataColumn url = new DataColumn("news_url", typeof(string));


            //add Column to Datatable
            dynamicTable.Columns.Add(id);
            dynamicTable.Columns.Add(heading);                
            dynamicTable.Columns.Add(url);

            //counter used for get fix no of news
            int counter = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                  dynamicRow = dynamicTable.NewRow();
                    //Add Rows to dymanicTable
                    dynamicTable.Rows.Add(dynamicRow);
                    //Assign Column value
                    dynamicTable.Rows[dynamicTable.Rows.Count - 1]["column_id"] = dt.Rows[i]["column_id"];
                    dynamicTable.Rows[dynamicTable.Rows.Count - 1]["column_heading"] = dt.Rows[i]["column_heading"];                    

                    dynamicTable.Rows[dynamicTable.Rows.Count - 1]["column_url"] = dt.Rows[i]["column_url"];


            }

            if (dynamicTable.Rows.Count != 0)
            {
                //Bind Data to repeater            
                XMLRepeater.DataSource = dynamicTable;
                XMLRepeater.DataBind();
            }
        }
        catch (Exception ee)
        {


        }
        finally
        {
            xmlreader.Close();
        }
    }
Ghost Answer
  • 1,458
  • 1
  • 17
  • 41
0

Thanks guys for your answers but after a lot of search i found exactly what i wanted. I wanted to change multiple pages footer section using single file without changing my pages name (from .html pages to other like .aspx,.php,.asp) All i needed to do was use SSI aka server side includes. The only thing you need to do is check if your server supports SSI or not and then make an individual html footer page that you want to include on every page. In order to include that external footer page just type.

<!--#include file="footer.html" -->

in the area,div,table wherever you want your footer to load and its done .

For detailed article pls go to following link http://httpd.apache.org/docs/2.2/howto/ssi.html

Bloomberg
  • 2,317
  • 2
  • 25
  • 47
0

Looks like he wanna do it client side. Maybe doesn't wanna enable PHP module.

Hikari
  • 3,797
  • 12
  • 47
  • 77