经典 ASP 是否有一个可用于浏览和修改服务器上 DOM 元素的对象?
我正在使用一个经典的 asp 应用程序,该应用程序需要修改用户复制并粘贴到表单中的代码的功能。该用户被认为是不熟悉 html 的受信任用户。
我试图做到这一点,以便如果用户想要更改所提供代码中的所有 width=""
属性,那么他所要做的就是用正确的值填充文本框标签 Width 并按保存/提交。然后,脚本将查找所有宽度属性并更新所提供的 html 代码片段中的值。
我一直在研究正则表达式来做到这一点,但在研究时我读到很多人不推荐使用正则表达式来处理此类事情,而宁愿使用某种 html 解析器对象。
经典 asp 中是否有可用的 html 解析器或 DOM 浏览器/编辑器,或者我只需要继续我的正则表达式开发?
对于正则表达式,这是我到目前为止所拥有的......仍然需要修改它以对所有匹配项执行替换,而不仅仅是第一个匹配项:
function replaceBetween(sSource, sStart, sStop, sValue)
thisNewValue = sStart & sValue & sStop
set re = new regexp
re.pattern = "(" & "" &sStart & ")(.*?)(" & sStop & ")"
re.IgnoreCase = true
response.write "Pattern: <b>" & re.pattern & "</b><br />" & vbnewline
response.write "thisNewValue: <b>" & thisNewValue & "</b><br />" & vbnewline
response.write "match: <b>" & re.test(sSource) & "</b><br />" & vbnewline
replaceBetween = re.replace(sSource, thisNewValue)
end function
sourceText = ("<div class='thisclass' id=""thisID""><a anotherthing="""" attribute=""one""><a attribute=""2""><a anotherattribute="" attribute=""three 3""></div>")
replacestart = "attribute="""
replacestop = """"
newvalue = "XXXX"
response.write "updated source: <b>" & server.HTMLEncode(replaceBetween(sourceText,replacestart,replacestop,newvalue)) & "</b><br />" & vbnewline
I am working in a classic asp application that requires functionality that will modify code that the user copy and pastes into a form. The user is considered a trusted user who is not familiar with html.
I am trying to make it so that if the user wants to change all width=""
attributes in the supplied code then all he has to do is fill a textbox label Width with the correct value and press save/submit. Then the script will find all width attributes and update their values in the html snippet that was supplied.
I've been working on a regular expression to do this, but while researching I read that a lot of people do not recommend regexps for this type of thing and would rather use a html parser object of some sort.
Is there an html parser or DOM browser/editor available in classic asp or do I just need to continue my regexp development?
For the regexp, this is what I have so far... still need to modify it to perform replacements on all matches, not just the first one:
function replaceBetween(sSource, sStart, sStop, sValue)
thisNewValue = sStart & sValue & sStop
set re = new regexp
re.pattern = "(" & "" &sStart & ")(.*?)(" & sStop & ")"
re.IgnoreCase = true
response.write "Pattern: <b>" & re.pattern & "</b><br />" & vbnewline
response.write "thisNewValue: <b>" & thisNewValue & "</b><br />" & vbnewline
response.write "match: <b>" & re.test(sSource) & "</b><br />" & vbnewline
replaceBetween = re.replace(sSource, thisNewValue)
end function
sourceText = ("<div class='thisclass' id=""thisID""><a anotherthing="""" attribute=""one""><a attribute=""2""><a anotherattribute="" attribute=""three 3""></div>")
replacestart = "attribute="""
replacestop = """"
newvalue = "XXXX"
response.write "updated source: <b>" & server.HTMLEncode(replaceBetween(sourceText,replacestart,replacestop,newvalue)) & "</b><br />" & vbnewline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 HTML 格式正确吗?如果是这样,您可以简单地使用 XML DomDocument。使用 XPath 查找要替换的属性。
实际上,您也可以在 ASP 中使用 JScript 服务器端,这可能会让您访问您可以使用的 HTMLDom 库。
Is your HTML well formed? If so you could simply use an XML DomDocument. Use XPath to find the attributes you want to replace.
You can actually use JScript serverside as well in ASP, whicdh might give you access to HTMLDom libraries you could use.