Javascript XML解析或替代 [英] Javascript XML parsing or alternative
问题描述
我正在为博客后端构建一个Javascript预览函数(很像本网站上使用的那个),我希望能够解析一些通常由PHP解析的自定义标记。我想知道是否可以使用JS XML解析器来解析textarea中的内容,如下所示:
I'm building a Javascript preview function for a blog back-end (much like the one used on this website), and I'd like to be able to parse some custom tags that normally get parsed by PHP. I am wondering if it's possible to use the JS XML parser to parse content from a textarea that would look like:
<img=1>
Use for
<url=http://apwit.com>testing</url>
purposes only!
我在这里读到另一个问题,因为使用正则表达式解析这样的事情是个坏主意因为可能有很多例外。您怎么看?
I read on another question here once that using regex to parse things like this is a bad idea because of the many many exceptions there could be. What do you think?
推荐答案
使用此: http://www.w3schools.com/Xml/tryit.asp?filename=tryxml_parsertest2
它从字符串解析xml并使用浏览器中的快速原生XML解析引擎。
It parses xml from a string and uses the fast native XML parsing engine from the browser.
解释和讨论:
http://www.w3schools.com/Xml/xml_parser.asp
这篇关于Javascript XML解析或替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!