Expand my Community achievements bar.

Removing node from xml when submitting form

Avatar

Former Community Member
I have a form that uses XML data connection (XML Schema). I use xml to prepopulate form and I embed image to form with xml but i don't want the image to be sent back after user submits the form. XML looks a bit like this:<br /><br /><?xml version="1.0" encoding="UTF-8"?><br /><App><br /><Image>image data</image><br /><Subform1>...</Subform1><br /><Subform2>...</Subform2><br /></App><br /><br />So one answer is using xslt to remove the Image node but even I tried to make one, it wouldn't work. I haven't used xslt before so there may be some error in it.<br />I tried to use javascript to unbind the imagefield runtime with two different ways (ImageField, form:ready event):<br />this.bind.match = "none";<br />or<br />this.bind.ref = "";<br />But this didn't work neither. Should I try to unbind it using xfa.record.Image ?<br /><br />Any help or example would be appreciated.<br />- Masi
2 Replies

Avatar

Former Community Member
This may be of help:






function removeXMLNode(strNodeName){

// XML nodes within 2nd indendation and below cannot be removed (Bug?), exception is thrown.

// Thus use try/catch.

try {

var objNode = xfa.record[strNodeName];

if (objNode){

xfa.record.nodes.remove(objNode);

}

}catch(e){

console.println("removing XML node named '"+ strNodeName +"' failed.");

}

}




You may call this method using something like
removeXMLNode("Subform1") prior to the form being submitted.

I could not get this to work with nodes deeper than a single level, ie.
form1.Subform1.SubSubform1 cannot be removed. I suppose, it's a bug.

Avatar

Former Community Member
Correction: there's no bug with removing XML nodes. There's a bug with my function :-o.

Use this instead:






function removeXMLNode(strNodePath){

var objNode = xfa.record[strNodePath];

if (objNode){

xfa.record[objNode.parent.name].nodes.remove(objNode);

}

}