freelanceprogrammers.org Forum Index » ASP
Parsing a RSS feed with RSS namespace
Joined: 24 Jun 2005
Posts: 4
Parsing a RSS feed with RSS namespace
Hello,
How do I parse a RSS feed with elements like <foo:bar ...> (like "<rdf:RDF
...>")?
How should the XPath query be?
The feed:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:syn="http://purl.org/rss/1.0/modules/syndication/">
<item rdf:about="http://www.myUrl.com/">
<title>myTitle</title>
<link>http://www.someUrl.com/</link>
<description>myDescription</description>
<dc:date>myDate</dc:date>
</item>
</rdf:RDF>
Here is my code. When myQuery = "/", I get all the content of the file. When
I try to select an item, I get 0 nodes returned. I think the problem is the
RDF namespace, but how do I fix it?
XPathDocument doc = new XPathDocument("http://localhost/myFeed.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator items = nav.Select(myQuery);
while (items.MoveNext())
{
Console.WriteLine(items.Current.Value.ToString());
}
Thanks in advance.
Helge
Joined: 24 Jun 2005
Posts: 4
Parsing a RSS feed with RSS namespace
Here is my code when I have tried to add the RDF namespace:
XmlTextReader reader = new
XmlTextReader("http://localhost/myFeed.xml");
XmlDocument xmlDoc = new XmlDocument();
XmlNamespaceManager nsmRequest = new
XmlNamespaceManager(xmlDoc.NameTable);
nsmRequest.AddNamespace("rdf",
"http://www.w3.org/1999/02/22-rdf-syntax-ns#");
nsmRequest.AddNamespace("rss", "http://purl.org/rss/1.0/");
XmlNodeList nodes = xmlDoc.SelectNodes("/rdf:RDF/item", nsmRequest);
Console.WriteLine(nodes.Count.ToString());
Still returning 0 nodes. why?
Helge
_____
From: AspNetAnyQuestionIsOk@yahoogroups.com
[mailto:AspNetAnyQuestionIsOk@yahoogroups.com] On Behalf Of Helge Thomas
Hellerud
Sent: 24. juni 2005 17:50
To: AspNetAnyQuestionIsOk@yahoogroups.com
Subject: [AspNetAnyQuestionIsOk] Parsing a RSS feed with RSS namespace
Hello,
How do I parse a RSS feed with elements like <foo:bar ...> (like "<rdf:RDF
...>")?
How should the XPath query be?
The feed:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#
<http://www.w3.org/1999/02/22-rdf-syntax-ns> "
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:syn="http://purl.org/rss/1.0/modules/syndication/">
<item rdf:about="http://www.myUrl.com/">
<title>myTitle</title>
<link>http://www.someUrl.com/</link>
<description>myDescription</description>
<dc:date>myDate</dc:date>
</item>
</rdf:RDF>
Here is my code. When myQuery = "/", I get all the content of the file. When
I try to select an item, I get 0 nodes returned. I think the problem is the
RDF namespace, but how do I fix it?
XPathDocument doc = new XPathDocument("http://localhost/myFeed.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathNodeIterator items = nav.Select(myQuery);
while (items.MoveNext())
{
Console.WriteLine(items.Current.Value.ToString());
}
Thanks in advance.
Helge
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
* To unsubscribe from this group, send an email to:
AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
<mailto:AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com?subject=Unsubscrib
e>
* Your use of Yahoo! Groups is subject to the Yahoo!
<http://docs.yahoo.com/info/terms/> Terms of Service.
[Non-text portions of this message have been removed]
Joined: 11 Jan 2006
Posts: 46
Parsing a RSS feed with RSS namespace
Two problems:
1) you are not loading anything into the document, you fill the
reader, but don`t load the xmlDoc object
2) rss is your default namespace, you need to include it in the XPath query
XmlNodeList nodes = xmlDoc.SelectNodes("/rdf:RDF/rss:item", nsmRequest);
On 6/24/05, Helge Thomas Hellerud <helgetho@...> wrote:
> Here is my code when I have tried to add the RDF namespace:
>
>
>
> XmlTextReader reader = new
> XmlTextReader("http://localhost/myFeed.xml");
>
> XmlDocument xmlDoc = new XmlDocument();
>
> XmlNamespaceManager nsmRequest = new
> XmlNamespaceManager(xmlDoc.NameTable);
>
> nsmRequest.AddNamespace("rdf",
> "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
>
> nsmRequest.AddNamespace("rss", "http://purl.org/rss/1.0/");
>
> XmlNodeList nodes = xmlDoc.SelectNodes("/rdf:RDF/item", nsmRequest);
>
> Console.WriteLine(nodes.Count.ToString());
>
>
>
> Still returning 0 nodes. why?
>
>
>
> Helge
>
>
>
>
>
>
>
> _____
>
> From: AspNetAnyQuestionIsOk@yahoogroups.com
> [mailto:AspNetAnyQuestionIsOk@yahoogroups.com] On Behalf Of Helge Thomas
> Hellerud
> Sent: 24. juni 2005 17:50
> To: AspNetAnyQuestionIsOk@yahoogroups.com
> Subject: [AspNetAnyQuestionIsOk] Parsing a RSS feed with RSS namespace
>
>
>
> Hello,
>
> How do I parse a RSS feed with elements like <foo:bar ...> (like "<rdf:RDF
> ...>")?
> How should the XPath query be?
>
> The feed:
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#
> <http://www.w3.org/1999/02/22-rdf-syntax-ns> "
> xmlns="http://purl.org/rss/1.0/"
> xmlns:dc="http://purl.org/dc/elements/1.1/"
> xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
> xmlns:admin="http://webns.net/mvcb/"
> xmlns:syn="http://purl.org/rss/1.0/modules/syndication/">
>
> <item rdf:about="http://www.myUrl.com/">
> <title>myTitle</title>
> <link>http://www.someUrl.com/</link>
> <description>myDescription</description>
> <dc:date>myDate</dc:date>
> </item>
> </rdf:RDF>
>
> Here is my code. When myQuery = "/", I get all the content of the file. When
> I try to select an item, I get 0 nodes returned. I think the problem is the
> RDF namespace, but how do I fix it?
>
> XPathDocument doc = new XPathDocument("http://localhost/myFeed.xml");
> XPathNavigator nav = doc.CreateNavigator();
> XPathNodeIterator items = nav.Select(myQuery);
>
> while (items.MoveNext())
> {
> Console.WriteLine(items.Current.Value.ToString());
> }
>
> Thanks in advance.
>
> Helge
>
>
>
>
> _____
>
> Yahoo! Groups Links
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
>
> * To unsubscribe from this group, send an email to:
> AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
> <mailto:AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com?subject=Unsubscrib
> e>
>
> * Your use of Yahoo! Groups is subject to the Yahoo!
> <http://docs.yahoo.com/info/terms/> Terms of Service.
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Joined: 24 Jun 2005
Posts: 4
Parsing a RSS feed with RSS namespace
Thanks! It worked!
_____
From: AspNetAnyQuestionIsOk@yahoogroups.com
[mailto:AspNetAnyQuestionIsOk@yahoogroups.com] On Behalf Of Dean Fiala
Sent: 24. juni 2005 18:57
To: AspNetAnyQuestionIsOk@yahoogroups.com
Subject: Re: [AspNetAnyQuestionIsOk] Parsing a RSS feed with RSS namespace
Two problems:
1) you are not loading anything into the document, you fill the
reader, but don`t load the xmlDoc object
2) rss is your default namespace, you need to include it in the XPath query
XmlNodeList nodes = xmlDoc.SelectNodes("/rdf:RDF/rss:item", nsmRequest);
On 6/24/05, Helge Thomas Hellerud <helgetho@...> wrote:
> Here is my code when I have tried to add the RDF namespace:
>
>
>
> XmlTextReader reader = new
> XmlTextReader("http://localhost/myFeed.xml");
>
> XmlDocument xmlDoc = new XmlDocument();
>
> XmlNamespaceManager nsmRequest = new
> XmlNamespaceManager(xmlDoc.NameTable);
>
> nsmRequest.AddNamespace("rdf",
> "http://www.w3.org/1999/02/22-rdf-syntax-ns#
<http://www.w3.org/1999/02/22-rdf-syntax-ns> ");
>
> nsmRequest.AddNamespace("rss", "http://purl.org/rss/1.0/");
>
> XmlNodeList nodes = xmlDoc.SelectNodes("/rdf:RDF/item", nsmRequest);
>
> Console.WriteLine(nodes.Count.ToString());
>
>
>
> Still returning 0 nodes. why?
>
>
>
> Helge
>
>
>
>
>
>
>
> _____
>
> From: AspNetAnyQuestionIsOk@yahoogroups.com
> [mailto:AspNetAnyQuestionIsOk@yahoogroups.com] On Behalf Of Helge Thomas
> Hellerud
> Sent: 24. juni 2005 17:50
> To: AspNetAnyQuestionIsOk@yahoogroups.com
> Subject: [AspNetAnyQuestionIsOk] Parsing a RSS feed with RSS namespace
>
>
>
> Hello,
>
> How do I parse a RSS feed with elements like <foo:bar ...> (like "<rdf:RDF
> ...>")?
> How should the XPath query be?
>
> The feed:
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#
<http://www.w3.org/1999/02/22-rdf-syntax-ns>
> <http://www.w3.org/1999/02/22-rdf-syntax-ns> "
> xmlns="http://purl.org/rss/1.0/"
> xmlns:dc="http://purl.org/dc/elements/1.1/"
> xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/"
> xmlns:admin="http://webns.net/mvcb/"
> xmlns:syn="http://purl.org/rss/1.0/modules/syndication/">
>
> <item rdf:about="http://www.myUrl.com/">
> <title>myTitle</title>
> <link>http://www.someUrl.com/</link>
> <description>myDescription</description>
> <dc:date>myDate</dc:date>
> </item>
> </rdf:RDF>
>
> Here is my code. When myQuery = "/", I get all the content of the file.
When
> I try to select an item, I get 0 nodes returned. I think the problem is
the
> RDF namespace, but how do I fix it?
>
> XPathDocument doc = new XPathDocument("http://localhost/myFeed.xml");
> XPathNavigator nav = doc.CreateNavigator();
> XPathNodeIterator items = nav.Select(myQuery);
>
> while (items.MoveNext())
> {
> Console.WriteLine(items.Current.Value.ToString());
> }
>
> Thanks in advance.
>
> Helge
>
>
>
>
> _____
>
> Yahoo! Groups Links
>
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
>
> * To unsubscribe from this group, send an email to:
> AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
>
<mailto:AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com?subject=Unsubscrib
> e>
>
> * Your use of Yahoo! Groups is subject to the Yahoo!
> <http://docs.yahoo.com/info/terms/> Terms of Service.
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
* To unsubscribe from this group, send an email to:
AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com
<mailto:AspNetAnyQuestionIsOk-unsubscribe@yahoogroups.com?subject=Unsubscrib
e>
* Your use of Yahoo! Groups is subject to the Yahoo!
<http://docs.yahoo.com/info/terms/> Terms of Service.
[Non-text portions of this message have been removed]
Joined: 25 Jun 2005
Posts: 5
Parsing a RSS feed with RSS namespace
I wanted to ask some of the gurus here about speed and building output with
literals. I can and already have this it is a matter of speed. It seems a
lot slower than aspclassic was but is basically doing the same thing. So far
there are about 750 records that it outputs. This takes a minute with the
code below. I have a aspclassic site in comparison that outputs 3000 records
and does it in 1/10th the time. Is there a way to speed this up? Thanks.
<CODE>
----------------------------------------------------------------------------
----
While objDataReader.Read()
`DATABASE FIELDS
strTotalSubscribers = strTotalSubscribers + 1
strUsername = objDataReader("Username")
strMembershipType = objDataReader("MembershipType")
strSitenameDB = objDataReader("Sitename")
strDateJoined = objDataReader("DateJoined")
strP_Updated = objDataReader("P_Updated")
strLastPaymentAmount = objDataReader("LastPaymentAmount")
strLastPaymentDate = objDataReader("LastPaymentDate")
strNextPaymentDueDate = objDataReader("NextPaymentDueDate")
`MembershipType Detection
If strMembershipType = "Premium Member" Then
strMembershipType = "<span style=`background-color:
#00FF00`>" & strMembershipType & "</span>"
ElseIf strMembershipType = "Standard Member" Then
Else `They aren`t logged in or aren`t a member.
End If
`Is Payment OverDue Detection
If strNextPaymentDueDate < DateTime.Now().ToShortDateString()
Then
strNextPaymentDueDate = "<span style=`background-color:
#FF0000`>" & strNextPaymentDueDate & "</span>"
Else `They aren`t logged in or aren`t a member.
End If
LiteralOutput.Text = LiteralOutput.Text & "<tr>"
LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
nowrap>"
LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
size=`1`>"
LiteralOutput.Text = LiteralOutput.Text & "<a target=`_blank`
href=`AdministratorUpdateSubscriber.aspx?username=" & strUsername &
"`>Edit</a></font><b><font face=`Verdana` size=`1`
color=`#000080`>|</font></b>"
LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
size=`1`><a target=`_blank`
href=`AdministratorDeleteSubscriber.aspx?username=" & strUsername &
"`>Delete</a></font>"
LiteralOutput.Text = LiteralOutput.Text & "<b><font
face=`Verdana` size=`1` color=`#000080`>|</font></b>"
LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
size=`1`><a target=`_blank` href=`s_profile.aspx?username=" & strUsername &
"`>View</a></font>"
LiteralOutput.Text = LiteralOutput.Text & "</td>"
LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
nowrap><font face=`Verdana` size=`1`><b><a href=`s_profile.aspx?username=" &
strUsername & "`>" & strUsername & "</a></b></font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`158`
align=`center` nowrap><font face=`Verdana` size=`1`>" & strSitenameDB &
"</font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`128`
align=`center` nowrap><font face=`Verdana` size=`1`>" & strMembershipType &
"</font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`70`
align=`center` nowrap><font face=`Verdana` size=`1`>" & strLastPaymentAmount
& "</font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
align=`center` nowrap><font face=`Verdana` size=`1`>" & strLastPaymentDate &
"</font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
align=`center` nowrap><font face=`Verdana` size=`1`>" &
strNextPaymentDueDate & "</font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
align=`center` nowrap><font face=`Verdana` size=`1`>" & strDateJoined &
"</font></td>"
LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
align=`center` nowrap><font face=`Verdana` size=`1`>" & strP_Updated &
"</font></td>"
End While
<CODE>
----------------------------------------------------------------------------
----
Joined: 11 Jan 2006
Posts: 46
Parsing a RSS feed with RSS namespace
There are many better ways to do this than updating the Text property
of a Literal control in a loop:
1) use a datagrid and bind it your datasource
2) use XML from the datasource and format with XSLT
3) pushing the strings directly to the page`s streamwriter (Response.Output)
4) build the string you want to output using the StringBuilder class
and then set the LiteralOutput.Text property with its .ToString()
method
Everytime you update a string .NET you are actually creating a new
string object. You are concatenating the LiteralOutput.Text property
repeatedly, in a loop. That`s going to be 1000s of objects created
that are thrown away almost instantly. Going with options 3 or 4 will
at least get you away from this situation. Options 1 or 2 will
leverage a lot of the benefits of .NET, pull your formatting out of
your code, and make it easier to read and maintain.
On 6/24/05, Mike Belcher
<AspNetAnyQuestionIsOk@...> wrote:
> I wanted to ask some of the gurus here about speed and building output with
> literals. I can and already have this it is a matter of speed. It seems a
> lot slower than aspclassic was but is basically doing the same thing. So far
> there are about 750 records that it outputs. This takes a minute with the
> code below. I have a aspclassic site in comparison that outputs 3000 records
> and does it in 1/10th the time. Is there a way to speed this up? Thanks.
>
>
> <CODE>
> ----------------------------------------------------------------------------
> ----
>
>
> While objDataReader.Read()
>
> `DATABASE FIELDS
> strTotalSubscribers = strTotalSubscribers + 1
> strUsername = objDataReader("Username")
> strMembershipType = objDataReader("MembershipType")
> strSitenameDB = objDataReader("Sitename")
> strDateJoined = objDataReader("DateJoined")
> strP_Updated = objDataReader("P_Updated")
> strLastPaymentAmount = objDataReader("LastPaymentAmount")
> strLastPaymentDate = objDataReader("LastPaymentDate")
> strNextPaymentDueDate = objDataReader("NextPaymentDueDate")
>
>
>
> `MembershipType Detection
> If strMembershipType = "Premium Member" Then
> strMembershipType = "<span style=`background-color:
> #00FF00`>" & strMembershipType & "</span>"
>
> ElseIf strMembershipType = "Standard Member" Then
>
> Else `They aren`t logged in or aren`t a member.
>
> End If
>
>
> `Is Payment OverDue Detection
> If strNextPaymentDueDate < DateTime.Now().ToShortDateString()
> Then
> strNextPaymentDueDate = "<span style=`background-color:
> #FF0000`>" & strNextPaymentDueDate & "</span>"
>
> Else `They aren`t logged in or aren`t a member.
>
> End If
>
>
>
> LiteralOutput.Text = LiteralOutput.Text & "<tr>"
> LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
> nowrap>"
>
> LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
> size=`1`>"
> LiteralOutput.Text = LiteralOutput.Text & "<a target=`_blank`
> href=`AdministratorUpdateSubscriber.aspx?username=" & strUsername &
> "`>Edit</a></font><b><font face=`Verdana` size=`1`
> color=`#000080`>|</font></b>"
> LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
> size=`1`><a target=`_blank`
> href=`AdministratorDeleteSubscriber.aspx?username=" & strUsername &
> "`>Delete</a></font>"
> LiteralOutput.Text = LiteralOutput.Text & "<b><font
> face=`Verdana` size=`1` color=`#000080`>|</font></b>"
> LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
> size=`1`><a target=`_blank` href=`s_profile.aspx?username=" & strUsername &
> "`>View</a></font>"
>
>
> LiteralOutput.Text = LiteralOutput.Text & "</td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
> nowrap><font face=`Verdana` size=`1`><b><a href=`s_profile.aspx?username=" &
> strUsername & "`>" & strUsername & "</a></b></font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`158`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strSitenameDB &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`128`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strMembershipType &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`70`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strLastPaymentAmount
> & "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strLastPaymentDate &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
> align=`center` nowrap><font face=`Verdana` size=`1`>" &
> strNextPaymentDueDate & "</font></td>"
>
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strDateJoined &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strP_Updated &
> "</font></td>"
>
> End While
>
>
> <CODE>
> ----------------------------------------------------------------------------
> ----
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Joined: 25 Jun 2005
Posts: 5
Parsing a RSS feed with RSS namespace
Is there a good tutorial on this or how would you do it with
StringBuilder class
then just saying LiteralOutput.Text = StringBuilder class basically.
I know how to do things in .net now but I know there are many ways to do
something abut some are faster and better than the other ones.
-----Original Message-----
From: AspNetAnyQuestionIsOk@yahoogroups.com
[mailto:AspNetAnyQuestionIsOk@yahoogroups.com] On Behalf Of Dean Fiala
Sent: Friday, June 24, 2005 4:42 PM
To: AspNetAnyQuestionIsOk@yahoogroups.com
Subject: Re: [AspNetAnyQuestionIsOk] Speed of output................
building literals..........
There are many better ways to do this than updating the Text property
of a Literal control in a loop:
1) use a datagrid and bind it your datasource
2) use XML from the datasource and format with XSLT
3) pushing the strings directly to the page`s streamwriter (Response.Output)
4) build the string you want to output using the StringBuilder class
and then set the LiteralOutput.Text property with its .ToString()
method
Everytime you update a string .NET you are actually creating a new
string object. You are concatenating the LiteralOutput.Text property
repeatedly, in a loop. That`s going to be 1000s of objects created
that are thrown away almost instantly. Going with options 3 or 4 will
at least get you away from this situation. Options 1 or 2 will
leverage a lot of the benefits of .NET, pull your formatting out of
your code, and make it easier to read and maintain.
On 6/24/05, Mike Belcher
<AspNetAnyQuestionIsOk@...> wrote:
> I wanted to ask some of the gurus here about speed and building output
with
> literals. I can and already have this it is a matter of speed. It seems a
> lot slower than aspclassic was but is basically doing the same thing. So
far
> there are about 750 records that it outputs. This takes a minute with the
> code below. I have a aspclassic site in comparison that outputs 3000
records
> and does it in 1/10th the time. Is there a way to speed this up? Thanks.
>
>
> <CODE>
>
----------------------------------------------------------------------------
> ----
>
>
> While objDataReader.Read()
>
> `DATABASE FIELDS
> strTotalSubscribers = strTotalSubscribers + 1
> strUsername = objDataReader("Username")
> strMembershipType = objDataReader("MembershipType")
> strSitenameDB = objDataReader("Sitename")
> strDateJoined = objDataReader("DateJoined")
> strP_Updated = objDataReader("P_Updated")
> strLastPaymentAmount = objDataReader("LastPaymentAmount")
> strLastPaymentDate = objDataReader("LastPaymentDate")
> strNextPaymentDueDate = objDataReader("NextPaymentDueDate")
>
>
>
> `MembershipType Detection
> If strMembershipType = "Premium Member" Then
> strMembershipType = "<span style=`background-color:
> #00FF00`>" & strMembershipType & "</span>"
>
> ElseIf strMembershipType = "Standard Member" Then
>
> Else `They aren`t logged in or aren`t a member.
>
> End If
>
>
> `Is Payment OverDue Detection
> If strNextPaymentDueDate < DateTime.Now().ToShortDateString()
> Then
> strNextPaymentDueDate = "<span style=`background-color:
> #FF0000`>" & strNextPaymentDueDate & "</span>"
>
> Else `They aren`t logged in or aren`t a member.
>
> End If
>
>
>
> LiteralOutput.Text = LiteralOutput.Text & "<tr>"
> LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
> nowrap>"
>
> LiteralOutput.Text = LiteralOutput.Text & "<font
face=`Verdana`
> size=`1`>"
> LiteralOutput.Text = LiteralOutput.Text & "<a target=`_blank`
> href=`AdministratorUpdateSubscriber.aspx?username=" & strUsername &
> "`>Edit</a></font><b><font face=`Verdana` size=`1`
> color=`#000080`>|</font></b>"
> LiteralOutput.Text = LiteralOutput.Text & "<font
face=`Verdana`
> size=`1`><a target=`_blank`
> href=`AdministratorDeleteSubscriber.aspx?username=" & strUsername &
> "`>Delete</a></font>"
> LiteralOutput.Text = LiteralOutput.Text & "<b><font
> face=`Verdana` size=`1` color=`#000080`>|</font></b>"
> LiteralOutput.Text = LiteralOutput.Text & "<font
face=`Verdana`
> size=`1`><a target=`_blank` href=`s_profile.aspx?username=" & strUsername
&
> "`>View</a></font>"
>
>
> LiteralOutput.Text = LiteralOutput.Text & "</td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
> nowrap><font face=`Verdana` size=`1`><b><a href=`s_profile.aspx?username="
&
> strUsername & "`>" & strUsername & "</a></b></font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`158`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strSitenameDB &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`128`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strMembershipType
&
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`70`
> align=`center` nowrap><font face=`Verdana` size=`1`>" &
strLastPaymentAmount
> & "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strLastPaymentDate
&
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
> align=`center` nowrap><font face=`Verdana` size=`1`>" &
> strNextPaymentDueDate & "</font></td>"
>
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strDateJoined &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strP_Updated &
> "</font></td>"
>
> End While
>
>
> <CODE>
>
----------------------------------------------------------------------------
> ----
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
Yahoo! Groups Links
Joined: 07 Jan 2006
Posts: 63
Parsing a RSS feed with RSS namespace
#1
StringBuilder
http://www.learnasp.com/freebook/learn/literalsrock.aspx
(note)
LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`>
size=`1`>"
even if you were not using stringbuilder
LiteralOutput.Text &= "<font face=`Verdana`> size=`1`>"
was better syntax for that.
#2
Also what you are doing below should be done with a repeater.
http://www.learnasp.com/freebook/learn/templates1.aspx
It should not be done with stringbuilder unless you just want to do
this in a very incorrect way faster. Literals were designed for small
things and you are using them for larger tasks that are much cleaner
to represent with repeaters.
#3
For some of your special cases (in your case "standard", "premium")
can be done in repeaters with stupid databinding tricks ala:
http://www.learnasp.com/freebook/learn/databindingtricks.aspx
You need to really wrap your mind around #2 and #3 to take the first
steps towards simplifying the tangled nature of coding ASP, rather
than ASP.net style.
On 6/24/05, Mike Belcher
<AspNetAnyQuestionIsOk@...> wrote:
> I wanted to ask some of the gurus here about speed and building output with
> literals. I can and already have this it is a matter of speed. It seems a
> lot slower than aspclassic was but is basically doing the same thing. So
> far
> there are about 750 records that it outputs. This takes a minute with the
> code below. I have a aspclassic site in comparison that outputs 3000
> records
> and does it in 1/10th the time. Is there a way to speed this up? Thanks.
>
>
> <CODE>
> ----------------------------------------------------------------------------
> ----
>
>
> While objDataReader.Read()
>
> `DATABASE FIELDS
> strTotalSubscribers = strTotalSubscribers + 1
> strUsername = objDataReader("Username")
> strMembershipType = objDataReader("MembershipType")
> strSitenameDB = objDataReader("Sitename")
> strDateJoined = objDataReader("DateJoined")
> strP_Updated = objDataReader("P_Updated")
> strLastPaymentAmount =
> objDataReader("LastPaymentAmount")
> strLastPaymentDate =
> objDataReader("LastPaymentDate")
> strNextPaymentDueDate =
> objDataReader("NextPaymentDueDate")
>
>
>
> `MembershipType Detection
> If strMembershipType = "Premium Member" Then
> strMembershipType = "<span style=`background-color:
> #00FF00`>" & strMembershipType & "</span>"
>
> ElseIf strMembershipType = "Standard Member" Then
>
> Else `They aren`t logged in or aren`t a member.
>
> End If
>
>
> `Is Payment OverDue Detection
> If strNextPaymentDueDate < DateTime.Now().ToShortDateString()
> Then
> strNextPaymentDueDate = "<span style=`background-color:
> #FF0000`>" & strNextPaymentDueDate & "</span>"
>
> Else `They aren`t logged in or aren`t a member.
>
> End If
>
>
>
> LiteralOutput.Text = LiteralOutput.Text & "<tr>"
> LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
> nowrap>"
>
> LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
> size=`1`>"
> LiteralOutput.Text = LiteralOutput.Text & "<a target=`_blank`
> href=`AdministratorUpdateSubscriber.aspx?username=" &
> strUsername &
> "`>Edit</a></font><b><font face=`Verdana` size=`1`
> color=`#000080`>|</font></b>"
> LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
> size=`1`><a target=`_blank`
> href=`AdministratorDeleteSubscriber.aspx?username=" &
> strUsername &
> "`>Delete</a></font>"
> LiteralOutput.Text = LiteralOutput.Text & "<b><font
> face=`Verdana` size=`1` color=`#000080`>|</font></b>"
> LiteralOutput.Text = LiteralOutput.Text & "<font face=`Verdana`
> size=`1`><a target=`_blank` href=`s_profile.aspx?username=" & strUsername &
> "`>View</a></font>"
>
>
> LiteralOutput.Text = LiteralOutput.Text & "</td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td align=`center`
> nowrap><font face=`Verdana` size=`1`><b><a href=`s_profile.aspx?username="
> &
> strUsername & "`>" & strUsername & "</a></b></font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`158`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strSitenameDB &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`128`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strMembershipType &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`70`
> align=`center` nowrap><font face=`Verdana` size=`1`>" &
> strLastPaymentAmount
> & "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strLastPaymentDate
> &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
> align=`center` nowrap><font face=`Verdana` size=`1`>" &
> strNextPaymentDueDate & "</font></td>"
>
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`86`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strDateJoined &
> "</font></td>"
> LiteralOutput.Text = LiteralOutput.Text & "<td width=`78`
> align=`center` nowrap><font face=`Verdana` size=`1`>" & strP_Updated &
> "</font></td>"
>
> End While
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







