1. #1
    Ext User
    Join Date
    Feb 2008
    Location
    Chilangolandia (Mexico City)
    Posts
    6
    Vote Rating
    0
    phreakermex is on a distinguished road

      0  

    Default Convert DOM XML Document to string

    Convert DOM XML Document to string


    Hi everyone!

    I've using the next function in order to convert a javascript XML object to string

    Code:
    function XMLtoString(elem){
    	
    	var serialized;
    	
    	try {
    		// XMLSerializer exists in current Mozilla browsers
    		serializer = new XMLSerializer();
    		serialized = serializer.serializeToString(elem);
    	} 
    	catch (e) {
    		// Internet Explorer has a different approach to serializing XML
    		serialized = elem.xml;
    	}
    	
    	return serialized;
    }
    Is there an easier way to perform the above function using ExtJS?
    And, also, when making an Ext.Ajax.request the params need to be string? Or can I pass directly a XML DOM object?

    Greetings!

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,004
    Vote Rating
    650
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    1) No, there isn't currently anything that does this.

    2) They can either be a string or a JS object.

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    You shoujld just be able to specify a document as the data using the xmlData option of http://extjs.com/deploy/dev/docs/?cl...member=request

    the XHR will convert it:

    http://www.w3.org/TR/XMLHttpRequest/#entity-body

  4. #4
    Ext User
    Join Date
    Feb 2009
    Posts
    18
    Vote Rating
    0
    LordLuky is on a distinguished road

      0  

    Talking Thanks!

    Thanks!


    Thank you for source code phreakermex :-). I'm using EXT GWT actually, but for XSLT transformation on Client I need JavaScript. In which I'm less then newbie.
    I could not handle JavaScriptObject in Java, but String is hunky-dory.

    Thanks!

  5. #5
    Ext User
    Join Date
    Dec 2010
    Posts
    1
    Vote Rating
    0
    Appeloappelo is on a distinguished road

      0  

    Default In Javascript for Selenium IDE reading XML from DOM to XMLString

    In Javascript for Selenium IDE reading XML from DOM to XMLString


    ...when you are reading/displaying a xml file in a browser:

    function loadXMLFromDOM2XMLString( xmlString, xmltag, currentChildNode ) {

    var nodes = currentChildNode.childNodes;
    var i = 0 ;
    var node = nodes[i];
    while ( i < nodes.length) {
    if (node.data == null) {xmltag = '<'+node.localName+'>';} else {xmltag = node.data;};
    xmlString = xmlString + xmltag;
    xmlString = loadXMLFromDOM2XMLString( xmlString, xmltag, node );
    if (node.data == null) {xmltag = '<'+'/'+node.localName+'>';} else {xmltag = "";};
    xmlString = xmlString + xmltag;
    i++;
    node = nodes[i];
    }
    return xmlString ;
    } ;

    var xmlString = "";
    var xmltag = "";
    var currentChildNode = window.document;

    xmlString = loadXMLFromDOM2XMLString( xmlString, xmltag, currentChildNode );
    xmlString;