C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » XML »

Reading xml document from html page.


Posted Date: 04 Nov 2009    Resource Type: Code Snippets    Category: XML
Author: krishnavenikaladiMember Level: Gold    
Rating: 1 out of 5Points: 12



the code snippet explains how to read the contents of xml and embed into webpage(using html)

step 1:
creating xml file with content
the following is xml file(product.xml)



<products>
<product>
<productid>101</productid>
<desc>TV</desc>
</product>
<product>
<productid>102</productid>
<desc>LAPTOP</desc>
</product>
<product>
<productid>103</productid>
<desc>MOBILE</descc>
</product>
<productid>104</productid>
<desc>WASHING MACHINE</descc>

<productid>105</productid>
<desc>OTHER GADGETS</descc>
</product>

</product>

</products>




explanation: the above xml simply shows the products in the mall

step 2:design html page with 2 text boxes & 2 buttons(first,next) .the buttons r used to navigate through the contents of xml.
the following code explains the concept




<html >
<head>
<title>Untitled Page</title>
//using javascipt
<script language ="javascript" >
//using fuction to move to first record
function f1()
{
p.recordset.MoveFirst()
}
//using unction to move to next & also checks whether if it is last
function f2()
{
p.recordset.MoveNext()
if(p.recordset.eof)
{
p.recordset.MoveLast()
alert ("LAST RECORD")
}
}
</script>
</head>
<body>
//creating xml tag to activate xmlparser
<xml id="p" src="C:\Documents and Settings\house\Desktop\product.xml">

</xml>

<form name="f1" >
//designing user interface and binding with data of xml
product id:<input type="text" name="t1" datasrc="#p" datafld="productid" />
<br />
product description:<input type="text" name="t1" datasrc="#p" datafld="desc" />
<br />
//calling of functions(java)
<input type ="button" name ="b1" value ="FIRST" onClick ="f1()" />
<input type ="button" name ="b2" value ="NEXT" onclick ="f2()" />

</form>
</body>
</html>





explanation:
-->the above code uses javascipt to move to first record using movefirst and next record using movenext
-->checks the end of record by eof(end of file)
-->using datasrc gives the datasource(here we r using id of xml whose src is set)
-->data is binded using datafld
scenario:
in some situations we just want only table with data rather than navigation
for that scenario the following snippet will accomplish the task

<html>

<body>
<xml id="p" src="C:\Documents and Settings\house\Desktop\product.xml">
</xml>
<table datasrc="#p" align="center" border="4">
<tr>
<td>prodid</td>
<td>desc</td>
</tr>
<tr>
<td><span datafld="productid"></td>
<td><span datafld="desc"></td>
</tr>
</table>
</body>
</html>

explanation:in the above scenario for table we r providing data source,binding is similar as the above.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Xml tag  .  Movenext  .  Movelast.eof  .  Datasrc  .  Datafls  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Bind XML to DataGrid
Previous Resource: Write XML to file
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use