开发者

xml <-> html conversion in javascript

开发者 https://www.devze.com 2023-02-04 19:15 出处:网络
What javascript framework/library may you advice if I want to convert HTML to XML and vice versa, by a set of rules?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号