Created
April 6, 2011 15:16
-
-
Save ggendre/905833 to your computer and use it in GitHub Desktop.
javascript : convert a string to XML DOM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this function convert the string representation of some XML | |
//into a DOM object. | |
function StringToXMLDom(string){ | |
var xmlDoc=null; | |
if (window.DOMParser) | |
{ | |
parser=new DOMParser(); | |
xmlDoc=parser.parseFromString(string,"text/xml"); | |
} | |
else // Internet Explorer | |
{ | |
xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); | |
xmlDoc.async="false"; | |
xmlDoc.loadXML(string); | |
} | |
return xmlDoc; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EXEMPLE FILE | |
//Ce bout de code retourne l'attribut url du premier tag image trouvé. | |
var xmlDom=StringToXMLDom(xmlString); | |
if (xmlDom){ | |
var tmp=xmlDom.getElementsByTagName("image")[0]; | |
if (tmp!=undefined){ | |
var src=tmp.getAttribute("url"); | |
if (src) return src; | |
} | |
} |
in a code outside windows... where does window
come from?
window.DOMParser
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use it,man ?