IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Move node in same parent Options · View
dacid
Posted: Tuesday, June 11, 2013 12:11:41 PM
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.
dacid
Posted: Wednesday, June 12, 2013 8:15:29 AM
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.
dacid
Posted: Friday, June 28, 2013 2:27:09 PM
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);
}
}
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.