Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2010
    Messaggi
    16

    Cross-Browser: Risettare il valore di un nodo

    Sto rendendo una funzione Cross-Browser e preferirei non cambiare gli input, per non dover andare a cambiare tutte le chiamate.
    questa funzione riceve come paramentro un path di un nodo e una stringa contenente un albero xml.
    Non riesco a trovare un modo di come cambiare il valore di un nodo

    codice:
    //sSimpleXPath="buildsets/buildset[setobject='SetPerson']/number"
    /*
    sXML="<buildsets><setsname>View</setsname><buildset><setobject>SetPerson</setobject><setname>Person</setname><number>0</number><selected>true</selected><defaultobject>Person</defaultobject><defaultxslt>formview</defaultxslt></buildset><buildset><setobject>SetPosition</setobject><setname>Position</setname><number>0</number><selected>false</selected><defaultobject>Position</defaultobject><defaultxslt>datasheet</defaultxslt></buildset></buildsets>"
    */
    function xmlNodeValue(sSimpleXPath, sXML, sNewValue)
    {
    		var oXML;
    		var parser;
    		if (window.DOMParser)
    		{
    			parser=new DOMParser();
    			oXML=parser.parseFromString(sXML,"text/xml");
    
                   if (sNewValue || sNewValue == 0)
    		{
    
    /* codice che funziona solo in IE
                            var oXML = new ActiveXObject("Microsoft.XMLDom");
    			oXML.async = false;
    			oXML.loadXML(sXML);
    			var oNode = oXML.selectSingleNode(sSimpleXPath);
    			if (sNewValue || sNewValue == 0)
    			{
    				if (oNode)
    				{
    					//return whole XML string if an update
    					oNode.text = sNewValue;
    					return oXML.xml; 
    }
    }
    */
    return (/*una stringa tipo sXML*/)
    }
    else
    {
    			var oNode = oXML.evaluate(sSimpleXPath, oXML, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    //return just the node is simply a 'fetch'
                            return oNode.singleNodeValue.textContent
    }
    Spero di esser stato chiaro
    e vi rigrazio in anticipo

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2010
    Messaggi
    16
    il comando era oNode.singleNodeValue.textContent = sNewValue;
    :-)

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.