count length of repeating node in loaded data

951 views
Skip to first unread message

billy

unread,
Jul 22, 2011, 2:50:43 PM7/22/11
to Adobe LiveCycle Developers
Hi all, i'm having a little trouble counting the number of a repeated
node in data that is loaded onto the form.
If i have an xml file that i am loading into the form that has a
structure like so

<root>
<child>
<grandchild>1</grandchild>
<child>
<child>
<grandchild>2</grandchild>
<child>
.....

and want to count the number of child nodes there are, i could do
something like this

xfa.resolveNode("xfa.datasets.data.root.child").length;

right? Thats what the documentation says at least, but i can't seem to
get it to work. Unfortunately I only have reader so i cant use the JS
debugger. I know i'm accessing the right path because if i put

xfa.resolveNode("xfa.datasets.data.root").saveXML("pretty");

it prints out the xml of the first instance.

If you guys could confirm or correct me that would be great.

Thanks

Nithyanandam Dharmadass

unread,
Jul 22, 2011, 4:11:35 PM7/22/11
to live...@googlegroups.com
The following expression should work..

xfa.resolveNode("xfa.datasets.data.root").nodes.length;

Try and let me know.

Nith

Martin Grimm

unread,
Jul 25, 2011, 7:17:04 AM7/25/11
to live...@googlegroups.com
Hi Billy,

you got it nearly right, you just missed an "s" and a "[*]" in your expression.

The correct expression is:

xfa.resolveNodes("xfa.datasets.data.root.child[*]").length

xfa.resolveNode() will always give you an object of type "node" (http://help.adobe.com/en_US/livecycle/9.0/designerHelp/000856.html) without a length property, while xfa.resolveNodes() will return a "list" (http://help.adobe.com/en_US/livecycle/9.0/designerHelp/000853.html).

The "[*]" in the XFA SOM expression denotes the selection of all like named sibling nodes (http://partners.adobe.com/public/developer/en/xml/xfa_spec_3_1.pdf#page=101). Without it the result will always be just "1" (or "0" if there is no element at all).

Hope that helps,

Martin

xfa.resolveNode("xfa.datasets.data.root.child").length;

Thanks

--
You received this message because you are subscribed to the Google Groups "Adobe LiveCycle Developers" group.
To post to this group, send email to live...@googlegroups.com.
To unsubscribe from this group, send email to livecycle+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/livecycle?hl=en.

billy

unread,
Jul 25, 2011, 1:43:05 PM7/25/11
to Adobe LiveCycle Developers
Awesome, thanks guys!

On Jul 25, 7:17 am, Martin Grimm <m...@eggs.de> wrote:
> Hi Billy,
>
> you got it nearly right, you just missed an "s" and a "[*]" in your expression.
>
> The correct expression is:
>
>         xfa.resolveNodes("xfa.datasets.data.root.child[*]").length
>
> xfa.resolveNode() will always give you an object of type "node" (http://help.adobe.com/en_US/livecycle/9.0/designerHelp/000856.html) without a length property, while xfa.resolveNodes() will return a "list" (http://help.adobe.com/en_US/livecycle/9.0/designerHelp/000853.html).
>
> The "[*]" in the XFA SOM expression denotes the selection of all like named sibling nodes (http://partners.adobe.com/public/developer/en/xml/xfa_spec_3_1.pdf#pa...). Without it the result will always be just "1" (or "0" if there is no element at all).
Reply all
Reply to author
Forward
0 new messages