|
|
Rank: Newbie
Joined: 12/1/2011 Posts: 9
|
Hello,
I'm using authentic browser. I want Move node in same parent, but i get error message on InsertChildBefore() function: XMLData: XMLData: invalid parameter specified
Quote: var noeudPrec = curNode.GetChild(idxPrec); var noeudFin = curNode.GetChild(idxFin); curNode.Parent.InsertChildBefore(noeudPrec, noeudFin);
I tried:
Quote: var noeud= objAuthView.CreateXMLNode(4); myBalise.Name = "td"; noeud = curNode.GetChild(idxDeb + i);
var noeudPrec = curNode.GetChild(idxPrec); curNode.InsertChildBefore(noeudPrec, noeud);
But i get this message: XMLData: XMLData: element already part of XMLData tree I'm thinking it's because it's the same parent.
Also, I tried to create new node since the original node:
Quote: var noeud= objAuthView.CreateXMLNode(4); myBalise.Name = "td"; var strXml = curNode.GetChild(idxDeb + i).GetTextValueXMLDecoded(); //alert(strXml); noeud.SetTextValueXMLEncoded(strXml);
var noeudPrec = curNode.GetChild(idxPrec); var noeudFin = curNode.GetChild(idxFin); //curNode.Parent.InsertChildBefore(noeudPrec, noeud);
But strXml is empty... :-(
Could you help me ?
Regards.
|
|
Rank: Newbie
Joined: 12/1/2011 Posts: 9
|
I found this:
Quote:Copying of existing XMLData objects If you want to insert existing XMLData objects at a different place in the same file, you cannot use the XMLData.InsertChild and XMLData.AppendChild methods. These methods only work for new XMLData objects. Instead of using InsertChild or AppendChild, you have to copy the object hierarchy manually. The following function written in JavaScript is an example for recursively copying XMLData: // this function returns a complete copy of the XMLData object function GetCopy(objXMLData) { var objNew; objNew = objPlugIn.CreateChild(objXMLData.Kind); objNew.Name = objXMLData.Name; objNew.TextValue = objXMLData.TextValue; if(objXMLData.HasChildren) { var objChild; objChild = objXMLData.GetFirstChild(-1); while(objChild) { try { objNew.AppendChild(GetCopy(objChild)); objChild = objXMLData.GetNextChild(); } catch(e) { alert("GetCopy: " + objChild.Name + "=" + e); objChild = null; } } } return objNew; } But i have this error messages: - GetCopy: Text=XMLData: XMLData: modification of element not allowed - GetCopy: emphasis=XMLData: no valid iterator exists (past last child)
The structure is copied, but not the text.
|
|
Rank: Newbie
Joined: 12/1/2011 Posts: 9
|
I rewrite the function getCopy() and the problem is solved:
// On ne peut pas réutiliser un noeud attribué, on est obligé de prendre une copie pour un éventuel déplacement. function copierNoeud(objAuthView, noeud) { var ret = createNoeud(objAuthView, noeud.Name); copieEnfants(objAuthView, noeud, ret); // Copier tous les enfants du noeud de référence dans celui de destination (attributs et balises enfants). return ret; } // Copier tous les enfants du noeud de référence dans celui de destination (attributs et balises enfants). function copieEnfants(objAuthView, parentOrig, parentDest) { try { var enfantOrig = parentOrig.GetFirstChild(-1); while (enfantOrig) { var enfantDest = objAuthView.CreateXMLNode(enfantOrig.Kind); // objAuthView GobjPlugIn.AuthenticView try { if (enfantOrig.Kind != 6) { //Text enfantDest.Name = enfantOrig.Name; } parentDest.AppendChild(enfantDest); if ((enfantOrig.Kind == 6) || (enfantOrig.Kind == 5)) { //text ou attribut enfantDest.TextValue = enfantOrig.TextValue; } /*if (enfantDest.Kind == 5) { enfantDest.TextValue = ''; enfantDest.TextValue = enfantOrig.TextValue; }*/ copieEnfants(objAuthView, enfantOrig, enfantDest); } catch (err) { //if ((err.number & 0xffff) == 1513); // last child reached //else throw (err); } enfantOrig = parentOrig.GetNextChild(); } } catch (err) { // if ((err.number & 0xffff) == 1504); // element has no children // else if ((err.number & 0xffff) == 1503) enfantOrig = null; // last child reached // else throw (err); } }
|
|
|
guest |