我们有以下经典的asp代码可以读取xml文件,当有超过10个并发请求到该页面时,它显示的性能很差,有人能够找出性能问题在此代码(我们知道的这是使用FileSystemObject的一个问题,但我们并没有为它的替代品!):如何优化这个从xml文件中读取的代码
set filesys=server.CreateObject("Scripting.FileSystemObject")
if filesys.FileExists(sourcefile) then
set source = Server.CreateObject("Msxml2.DOMDocument")
source.validateOnParse = false
source.resolveExternals = false
source.preserveWhiteSpace = false
source.load(sourcefile)
If source.ParseError.errorCode <> 0 Then
str_head=source.selectSingleNode("/LIST/ITEM/NEWSITEM/HEADLINE//").text
str_by=source.selectSingleNode("//LIST//ITEM//NEWSITEM//PROVIDER//").text
News_date_orig = source.selectSingleNode("/LIST/ITEM/NEWSITEM/CREATED//").text
str_date= formatdatetime(source.selectSingleNode("//LIST//ITEM//NEWSITEM//CREATED//").text,1)
set bodyNode=source.selectSingleNode("/LIST/ITEM/NEWSITEM//BODY//")
styleFile=Server.MapPath("/includes/xsl/template.xsl")
Set style = Server.CreateObject("Msxml2.DOMDocument")
style.validateOnParse = false
style.resolveExternals = false
style.preserveWhiteSpace = false
style.load(styleFile)
news_full = bodyNode.transformNode(style)
if len(news_full) < 10 then
news_full = str_abstract
end if
DiscriptionKeyWord = stripHTMLtags(news_full)
DiscriptionKeyWord=StrCutOff(DiscriptionKeyWord, 200, "...")
headerTitle=str_head
Set style=nothing
Set source = nothing
end if
set filesys= nothing
以下是stripHTMLtags功能:
Function stripHTMLtags(HTMLstring)
Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "<[^>]+>"
.IgnoreCase = True
.Global = True
End With
stripHTMLtags = RegularExpressionObject.Replace(HTMLstring, "")
Set RegularExpressionObject = nothing
End Function
UPDATE:我放置了一个计时器来显示读取xml文件的函数的执行时间,发现在生产服务器上需要大约3秒钟,而在我的PC上需要不到1秒钟的时间!这是什么意思?我迷路了。
我不认为stripHTMLtags的原因,在这里它的身体:功能stripHTMLtags(HTMLstring) \t设置RegularExpressionObject =新的RegExp \t随着RegularExpressionObject \t .Pattern = “<[^>] +>” \t .IgnoreCase =真 \t。环球=真 \t尾随着 \t stripHTMLtags = RegularExpressionObject.Replace(HTMLstring, “”) \t设置RegularExpressionObject =什么 端功能 – Cassini 2012-01-02 07:08:14
@Cassini:评论是不要把代码的好地方。请编辑您的问题,并在其中包含“stripHTMLTags”的代码。 – AnthonyWJones 2012-01-02 13:10:41
编辑...正如你可以看到它使用reguler表达式。 – Cassini 2012-01-02 17:33:29