Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

correct usage of resolveNode (static code works, dynamic not)

Avatar

Level 3

Hello,

I try to optimize my coding by using variables and constants.

I successfully read the “xml-input” of my form.

“xml-input” is (in my understanding) the data which was included into the form when it was generated

e.g.

<PERSON>

            <DATA>

                        <FIRSTNAME>Jack</FIRSTNAME>

                        <LASTNAME>Black</LASTNAME>

            </DATA>

<DATA>

                        <FIRSTNAME>Mike</FIRSTNAME>

                        <LASTNAME>Spike</LASTNAME>

            </DATA>

</PERSON>

Coding (it is not as simple as described down below in my form, but the idea is the same):

var xmlTable = “PERSON

myXML = new XML(trimXML(xfa.datasets.data.data.resolveNode(xmlTable).saveXML()))

// here it works. I only need to change PERSON to XY to use the same coding for anything else

var namePersonTwo = myXML.DATA[1]. LASTNAME;

// Output = “Spike”. Well it works in static version

// now more dynamic

var xmlTag = “LASTNAME”;

var namePersonTwo = myXML.DATA[1]. resolveNode(xmlTag);

// ERROR – resolveNode ist not a function

So how do I use resolveNode in this case. After all it worked above?!


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
1 Reply

Avatar

Level 10

Hi,

You seem to have a mix of XFA referencing (the resolveNode method) and an E4X referencing.  In your example myXML is a object of type "xml" (try doing a console.println(typeof(myXML)).  The xml object does not have a resolveNode method so you get the error.

To use E4X in your example (if I understand it correctly) you need to use the child method, something like;

var s = '<PERSON><DATA><FIRSTNAME>Jack</FIRSTNAME><LASTNAME>Black</LASTNAME></DATA><DATA><FIRSTNAME>Mike</FIRSTNAME><LASTNAME>Spike</LASTNAME></DATA></PERSON>';
myXML = new XML(s);
var ii = 1;
var xmlTag;
xmlTag = "FIRSTNAME";
console.println(myXML.DATA[ii].child(xmlTag));
xmlTag = "LASTNAME";
console.println(myXML.DATA[ii].child(xmlTag));

I am kind of curious why you would use E4X in this case, when it looks like you could have stuck with the XFA referencing.

Anyway hope this helps.

Bruce