Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Delete node from XML

Avatar

Level 2

Dear adobe experts,

I have a requirement to delete a node in the interface XML of an adobe form (not just deleting a subform on the form). It must be a delete, an empty node will not work (I've read this in another post).

The XML structure looks like this:

<ELEMENT>

     <DATA>

          <ROW_IID>0</ROW_IID>

          <PARENT>0</PARENT>

          <CHILD>0</CHILD>

     </DATA>

     <DATA>

          <ROW_IID>1</ROW_IID>

          <PARENT>0</PARENT>

          <CHILD>0</CHILD>

     </DATA>

</ELEMENT>

I want, for instance, to delete the second data node including the underlying elements: row_iid,parent & child. I already tried: xfa.record.nodes.remove(oRemoveNode); I got it from http://partners.adobe.com/public/developer/en/xml/Adobe_XML_Form_Object_Model_Reference.pdf and several posts from this forum but I keep getting the following message in the error console: removal failed. I know that the somexpression is correct.

Here is the code I used to try to remove the node.

var node_loc;

var del_node;

node_loc = "xfa.record.ELEMENT.DATA[1]";

del_node = xfa.resolveNode(node_loc);

xfa.record.nodes.remove(del_node);

Does anyone know what I've been doing wrong?

Kind regards,

Niels

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi Steve,

I fixed it myself. I adjusted my code a bit and now the node, including elements, is correctly removed.

Here's the way that I fixed it:

var node_loc;

var del_node;

node_loc = "xfa.record.ELEMENT.DATA[1]";

del_node = xfa.resolveNode(node_loc);

xfa.record.ELEMENT.nodes.remove(del_node);

Thanks for help!

Kind regards,

Niels

View solution in original post

5 Replies

Avatar

Former Community Member

You can use an Execute Script method. patExecContext.getProcessDataValue for your xml will return a org.w3c.dom.Node. Look up JavaDocs on that. Loop through the children and find the Node you want to delete. Use parentNode.removeChild(childNode).

Avatar

Level 2

Thanks Steve,

I will try this asap. I'll keep you informed on the progress.

Do you know why my code is not working?

Kind regards,

Niels

Avatar

Former Community Member

I know absolutely you cannot add a second child node of the same name with XPath. I would assume you can't delete one either. I now use Execute Script steps quite a bit instead of Set Value steps. If you set 8 values in a row in a Set Value and the 5th one fails, you don't know that, just that one of them did. If the exact same thing was done in an Execute Script with 8 patExecContext.setProcessDataStringValue lines, the error in the server log would indicate the 5th line failed. You can also put System.out.println() in an Execute Script to help debug logic errors.

I created a stubbed out Java class called patExecContext and a wrapper class that I can write BeanShell (What Execute Script uses) in. I can then work on the code in Eclipse with context helpers and syntax checking. I then copy the code out and paste into the Execute Script step. BTW, you can Google Bean Shell to learn more about what you can do like referencing additional jars, etc.

Avatar

Correct answer by
Level 2

Hi Steve,

I fixed it myself. I adjusted my code a bit and now the node, including elements, is correctly removed.

Here's the way that I fixed it:

var node_loc;

var del_node;

node_loc = "xfa.record.ELEMENT.DATA[1]";

del_node = xfa.resolveNode(node_loc);

xfa.record.ELEMENT.nodes.remove(del_node);

Thanks for help!

Kind regards,

Niels

Avatar

Former Community Member

I don't know why I was thinking this was on the process side.