Hi
I am new to ASP and am not sure where I am going wrong.
I have a simple program which displays data from an XML file. This works fine when run on windows console but I get the following error when I try to run the code(modified for asp) on a remote server:
CS1519: Invalid token 'while' in class, struct, or interface member declaration
Line 16: public string Result;
Line 17:
Line 18: while (iterator.MoveNext())
Line 19: {
Line 20: XPathNavigator nav2 = iterator.Current.Clone();
Here is my code:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.XPath" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
string fileName = Server.MapPath("news/news.xml");
XPathDocument docu = new XPathDocument(fileName);
XPathNavigator nav = docu.CreateNavigator();
// Compile a standard XPath expression
XPathExpression expr = nav.Compile("news/story[1]");
XPathNodeIterator iterator = nav.Select(expr);
public string Result;
while (iterator.MoveNext())
{
XPathNavigator nav2 = iterator.Current.Clone();
nav2.MoveToFirstChild();
Result = "title " + nav2.Value + "<br/>";
nav2.MoveToNext();
Result += "artist " + nav2.Value + "<br/>";
nav2.MoveToNext();
Result += "price " + nav2.Value + "<br/>";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Reading an XML File and attributes using XmlReader</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(Result); %>
</div>
</form>
</body>
</html>
I'd appreciate any assistance.
Thanks in advance.