본문 바로가기
Programming/JavaScript

[jquery] xml <--> string parsing

by 막이 2014. 10. 14.
  1. Parse XML to String

    1. <script type="text/javascript" language="javascript">
    2. function XMLToString(oXML)
    3. {
    4. //code for IE
    5. if (window.ActiveXObject) {
    6. var oString = oXML.xml; return oString;
    7. }
    8. // code for Chrome, Safari, Firefox, Opera, etc.
    9. else {
    10. return (new XMLSerializer()).serializeToString(oXML);
    11. }
    12. }
    13. </script>

    Parse String to XML

    1. <script type="text/javascript" language="javascript">
    2. function StringToXML(oString) {
    3. //code for IE
    4. if (window.ActiveXObject) {
    5. var oXML = new ActiveXObject("Microsoft.XMLDOM"); oXML.loadXML(oString);
    6. return oXML;
    7. }
    8. // code for Chrome, Safari, Firefox, Opera, etc.
    9. else {
    10. return (new DOMParser()).parseFromString(oString, "text/xml");
    11. }
    12. }
    13. </script>