XML DataBind Not working

Hi,

I have followed steps in multiple tutorials to data bind my XML data to a HTML table, but it does not display any records.

Does any body know of why this may be?

Thanks in advance

Andrew
LVL 20
REA_ANDREWAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

smaccariCommented:
Maybe your code could help us find your problem.
0
nabsolCommented:
Hi

Hope this helps!

http://www.devpapers.com/article/269

By Nab
0
REA_ANDREWAuthor Commented:
ok here is the code for the page which displays and adds to the XML file

<html>

<head>
<script language="javascript">
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sndReq(title,link,body) {
      document.getElementById("loading").style.display='';
    http.open('get', 'xmlSave.asp?title='+title+'&link='+link+'&body='+body);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        //if(response.indexOf('|' != -1)) {
        //    update = response.split('|');
        //    document.getElementById(update[0]).innerHTML = update[1];
        //}
        document.getElementById("loading").style.display='none';
        document.getElementById("foo").innerHTML = response;
       
    }
}

</script>
<title>New Page 1</title>
</head>

<body>

<div id="news" style="float:right;">
<xml id="NewsIT" src="newsfeed.xml" ASYNC="false"></xml>

<table border="1" >

<thead>
<tr><th>Date</th><th>Title</th><th>Link</th></tr>
</thead>

<tfoot>
<tr><th colspan="3">This is my BLOG</th></tr>
</tfoot>

<tr>
<td><span datasrc="#NewsIT" datafld="Date"></span></td>
<td><span datasrc="#NewsIT" datafld="Title"></span></td>
<td><span datasrc="#NewsIT" datafld="Link"></span></td>
</tr>
<tr>
<td colspan="3"><span datasrc="#NewsIT" datafld="Body"></span></td>
</tr>

</table>
  <div id="foo">
  </div>
</div>
<form method="POST" name="form1" action="">
  <p>Title<br>
  <input type="text" name="T1" size="20"></p>
  <p>Link<br>
  <input type="text" name="T2" size="44"></p>
  <p>Body<br>
  <textarea rows="7" name="S1" cols="37"></textarea></p>
 <a href="javascript:sndReq(document.form1.T1.value,document.form1.T2.value,document.form1.S1.value)">Add News Item</a><div id="loading" style="display:none;">....loading, please wait</div>
</form>

</body>

</html>
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

REA_ANDREWAuthor Commented:
It adds to the XML file no problem. It is the retrieving of the data that is not working
0
Ivo StoykovCommented:
Hello REA_ANDREW,

put datasrc into you table tag, i.e.
<table border="1" datasrc="#NewsIT" id="tbl">

and remove it from your span tags

check newsfeed.xml what's in and how it is loaded...

HTH

I
0
REA_ANDREWAuthor Commented:
I have amened as you said.  Although still nothing is showing. Here is my XML file, there may be an error in there as I have never worked with it before

http://www.nwcms.co.uk/andy/xml/newsfeed.xml
0
nabsolCommented:
Hi

This is how binding works:

< ?xml version="1.0" ?>
<!--  Filename - contact.xml  -->
<contact>
 <party>
  <name>Chief Programmabilities</name>
  <email>bgates@programmabilities.com</email>
  <organization>Programmabilities</organization>
  <address>1 Programmabilities Complex</address>
  <phone>1-661-716-2564 x7678</phone>
  <im>bgates@programmabilities.com</im>
  <url>http://programmabilities.com/</url>
  <p xmlns="http://programmabilties.com/contact.php">
    Contact</p>
 </party>
</contact>



<html><header><title>Contact</title></header><body>
  <!-- Contact module -->
  <xml id="Contact"
         src="http://programmabilities.com/xml/contact.xml"/>
  <table cellpadding="0" cellspacing="0" border="0"
         datasrc="#Contact">
   <tr>
    <td><strong>Name</strong>:</td>
    <td><div dataFld="name"/></td>
   </tr>
   <tr>
    <td><strong>Address</strong>:</td>
    <td><div dataFld="address"/></td>
   </tr>
   <tr>
    <td><strong>Mail</strong>:</td>
    <td><div dataFld="email"/>
    </td>
   </tr>
   <tr>
    <td><strong>IM</strong>:</td>
    <td><div dataFld="im"/></td>
   </tr>
   <tr>
    <td><strong>URL</strong>:</td>
    <td><div dataFld="url"/></td>
   </tr>
  </table>
  <!-- END Contact module -->
</body></html>


But in your case I think problem is that you have one tag field with changing id.

Nab
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ivo StoykovCommented:
Hi REA_ANDREW,

you have to put as a datafld the name of the fields in you XML file, i.e.

<span datafld="name">&nbsp</span>
this way the span will extract and show the name from your XML file on each table row...

regards

I
0
nabsolCommented:
Hi

I think to solve problem . You have to put datasrc in table tag as shown in example and change your xml
Hi

Why not you do this:

 <NewsItem>
<Date taborder="1">Date</Date>
<Title taborder="2">Title</Title>
<Link taborder="3">Link</Link>
<Body taborder="4">test</Body>
</NewsItem>
<NewsItem>
    .
    .
    .
    .
    .


and put datafld like this : <span dataFld="Date">

Hope this helps ! :-)


By Nab
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.