Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Delete node from XML

nvdm1
Level 2
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
nvdm1
Correct answer by
Level 2
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
yodadobe
Level 6
Level 6

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).

nvdm1
Level 2
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

yodadobe
Level 6
Level 6

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.

nvdm1
Correct answer by
Level 2
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

yodadobe
Level 6
Level 6

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