I'm loading an xml file with jQuery ajax loader, and need to convert it to a string so that I can save it out again using PHP post variables. What is the best way to do this?
<script type='text/javascript'> jQuery.ajax({ type: "GET", url: "data.xml", dataType: "xml", success: parseXML }); function parseXML(xml) { var xml_string = jQuery(xml).text(); // (This doesn't work- returns tagless, unformatted text) alert(xml_string); } </script>
The parseXML() method in jQuery is used to parse a string into an XML document. It uses native methods of the browser for creating a valid XML document. This valid XML document can be passed to jQuery for creating a jQuery object that can be manipulated or traversed.
jQuery can be used for XML processing on the Web as well as HTML processing, and in this article I show some examples of this use.
Json: JSON is a text format that is completely language independent. JQuery:It is a fast and minified JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.
Here it is:
<script type='text/javascript'> function xmlToString(xmlData) { var xmlString; //IE if (window.ActiveXObject){ xmlString = xmlData.xml; } // code for Mozilla, Firefox, Opera, etc. else{ xmlString = (new XMLSerializer()).serializeToString(xmlData); } return xmlString; } </script>
Taken from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With