xml <-> html conversion in javascript
What javascript framework/library may you advice if I want to convert HTML to XML and vice versa, by a set of rules?
e.g.
<a type="foo">
<b>bar<sth x="42"/></b>
</a>
to
<div class="a type-foo">
<div class="b">bar<span class="sth">42</span></div>
</div>
I used to traverse DOM by JQuery and build everything manually - lot of functions for every possible tag. What is 开发者_运维百科a shorter solution? E.g. I want to say "<a>
converts to <div class="a">
" etc. and then run something like htmlToXml()
or xmlToHtml()
.
if your HTML is a valid XHTML you can write an XSL transformation and apply it with javascript. Take a look here: http://www.w3schools.com/xsl/xsl_client.asp
精彩评论