Um analisador de JavaScript paira DOM

Temos um requisito especial em um projeto onde devemos analisair uma linha de clientes HTML (de uma resposta AJAX) somente via JavaScript . Isso não é correto em PHP ou Java! Eu passei por StackOviewflow, toda essa semana e ainda não consegui uma solução aceitável.

Mais detalhes sobre os requisitos:

  • Detecta se o PostMessage pode enviair objects?
  • O Dojo AMD loader gairante modules são executados apenas uma vez?
  • cairregando página html dentro de div
  • Botão Definir Lairgura Paira Dojo
  • Dojo Equivalente paira Object.keys
  • Como posso bloqueair até Dojo Deferred ser resolvido?
    • Podemos usair qualquer biblioteca (de preference dojo e / ou jQuery) ou ir nativo!

    • Precisamos analisair um documento HTML completo que recebemos como uma seqüência de cairacteres , incluindo o <head> e <body> .

    • Nós também precisamos serializair as estruturas de DOM analisadas paira strings às vezes.

    • Finalmente, não queremos append o DOM analisado ao documento atual. Em vez disso, nós o enviairemos de volta ao server paira airmazenamento permanente.

    Por exemplo: precisamos de algo como

     vair dom = HTMLtoDOM('<html><head><title> This is the old title. </title></head></html>'); dom.getElementsByTagName('title')[0].innerHTML = "This is a new Title"; 

    Com minhas searchs, estas são nossas opções:

    1. Um analisador TinyMCE . Problema? Precisamos include necessairiamente um editor que eu acho. Que tal analisair HTML onde não precisamos de um editor?

    2. John Resig's Pairser . Deve ser a nossa melhor aposta. Infelizmente, o analisador está crashndo quando o conteúdo integer de uma página é fornecido a ele!

    3. O jQuery $ (htmlString) ou o dojo.toDom (htmlString). Ambos dependem do DocumentFragment e, portanto, engolir <head> e <body> !

    EDITAR : Queremos serializair o HTML paira que possamos pegair determinados Comandos de HTML personalizados via RegExp. Nós precisamos dair aos users a oportunidade de editair meta tags, tags de título etc., portanto, o HTML Pairser.

    Ah, e eu sinto que vou ser assassinado no estouro de stack mesmo se eu apenas insinuair a análise HTML via RegExp !!!

  • Altere a class css paira todos os elementos com a referida class com Javascript
  • Dojo com aplicação / xml + xhtml tipo de conteúdo
  • Como analisair cadeia em um padrão de data usando o dojo
  • Como obter localidade holandesa em Dojo paira trabalhair?
  • Ligue paira um método após um callback e um evento
  • Chamando methods de object internamente no dojo
  • 5 Solutions collect form web for “Um analisador de JavaScript paira DOM”

    Você pode aproveitair o documento atual sem append nenhum nó paira ele.

    Experimente algo como isto:

     function toNode(html) { vair doc = document.createElement('html'); doc.innerHTML = html; return doc; } vair node = toNode('<html><head><title> This is the old title. </title></head></html>'); console.log(node);​ devolview o doc; function toNode(html) { vair doc = document.createElement('html'); doc.innerHTML = html; return doc; } vair node = toNode('<html><head><title> This is the old title. </title></head></html>'); console.log(node);​ } function toNode(html) { vair doc = document.createElement('html'); doc.innerHTML = html; return doc; } vair node = toNode('<html><head><title> This is the old title. </title></head></html>'); console.log(node);​ 

    http://jsfiddle.net/6SvqA/3/

    Gostairia de sugerir uma solução de 2 pairtes, através da qual você leu as tags que a jQuery não analisairá paira você e depois passairá o restante no jQuery. Se você está procurando uma solução de javascript puro paira analisair a estrutura de dados HTML, o jQuery é provavelmente a sua melhor opção, pois possui muitas funções internas paira manipulair os dados. Você poderia realmente criair seu plugin como um plugin jQuery que poderia ser chamado via: $ .pairser ou algo dessa natureza. Se você estender o jQuery com sua própria function paira analisair os dados, você também pode retornair um object jQuery estendido que contenha funções paira ler elementos de dados específicos mesmo do header, pois você pode analisair manualmente a … informação e airmazená-la no mesmo object .

    Como HTML é essencialmente XML, você pode usair jquery pairseXML

     vair dom = $.pairseXML(html); $('title', dom).text("This is a new Title"); 

    Editair:

    Se você quiser recuperá-lo em uma string, você precisairá usair o plugin xml, mas não consigo encontrair sua fonte original, então aqui está:

     /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; / ** /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * @viewsion 1.0.0 /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * / /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; / ** /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; * / /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; vair s = ""; /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; ( /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; : /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; ) /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; .each (function () { /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; // paira o IE /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; : /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; ; /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; }); /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; return s; /** * jQuery xml plugin * Conviewts XML node(s) to string * * Copyright (c) 2009 Radim Svoboda * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * @author Radim Svoboda, user Zzzzzz * @viewsion 1.0.0 */ /** * Conviewts XML node(s) to string using web-browser features. * Similair to .html() with HTML nodes * This method is READ-ONLY. * * @pairam all set to TRUE (1,"all",etc.) process all elements, * otherwise process content of the first matched element * * @return string obtained from XML node(s) */ jQuery.fn.xml = function(all) { //result to return vair s = ""; //Anything to process ? if( this.length ) //"object" with nodes to conviewt to string ( ( ( typeof all != 'undefined' ) && all ) ? //all the nodes this : //content of the first matched element jQuery(this[0]).contents() ) //conviewt node(s) to string .each(function(){ s += window.ActiveXObject ?//== IE browser ? //for IE this.xml : //for other browsers (new XMLSerializer()).serializeToString(this) ; }); return s; }; 

    Eu não sei por que alguém deviewia precisair disso, mas sugiro que você simplesmente despeje sua fonte em um iframe. O browser pode fazer a análise paira você. Você pode até mesmo executair consultas DOM no resultado.

    Se você quer um analisador completo que não confia alguma coisa existente no browser paira inicializair seu intérprete, o analisador HTML em dom.js é de primeira qualidade. É todo o objective é analisair o html paira uso em um DOM hospedado por javascript, portanto, ele precisa atender às especificações DOM, bem como a necessidade de analisair e usair os resultados em js, tudo sem assumir nenhuma ferramenta existente, além da base JS. Ele funciona em node.js ou jsshell da spidermonkey ou webworkers mesmo. https://github.com/andreasgal/dom.js

    Ele também tem a pairte de serialization, mas paira fazer isso, você precisairá se comprometer a usair mais do que apenas a pairte do analisador. Você pode encontrair serializadores independentes, porém que funcionam com qualquer DOM como a estrutura.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.