Expand my Community achievements bar.

SOLVED

how to get the nodes length and sub nodes .

Avatar

Former Community Member

Hi ,

find the scenario below .

<List1>

<List>

      <List1>

      <List1>

      <List1>

  </List>

<List>

      <List2>

      <List2>

      <List2>

  </List>

--

--

-

-

-

--</list1>

Here the list tag will be grow based on the I/p . Now what i want is how to get the length of <list >tag .

To implement above i used below code

var count = xfa.record.List1.List[0].nodes.length ; (Not working )

But if  var count = xfa.record.List1.nodes.length ; (working )

and also i want to remove some tag inside the <List > tag . How ?

Very Urgent .

Advance thanks .

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yes you need to use the name instead of value to get the tag name..

     xfa.datsets.data.Root.nodes.item(0).name

Thanks

Srini

View solution in original post

9 Replies

Avatar

Former Community Member

In the first example you give the [] cause an issue for javascript as those are reserved for arrays. You can use the xfa.resolveNode("string") to get to your instance....something like this:

var count = xfa.resolveNode("xfa.record.List1.List[0]").nodes.length ;

Now using this syntax you can replace the occurance number with a variable and put it in a for loop:

for (i=0;i<= 10;i++){

     count = xfa.resolveNode("xfa.record.List1.List[" + i + "]").nodes.length

}

Hope that helps

Paul

Avatar

Former Community Member

while doing like belo w,

var count = xfa.resolveNode("xfa.record.List1.List[0]").nodes.length ;

the line not excuting

and if i use

var count = xfa.resolveNode("xfa.record.List1.List[0]").

then its returning value .

I hope anyone worked ealier linke this

Avatar

Former Community Member

Just looked at a couple of Data dom manipulation forms I have done before and I use

the following code:

var currentElement;
var obj;

//Get the nodes below the root node in the dataDom
obj = xfa.datasets.data.root.nodes;

//Set an initial value for the textField
TextField1.rawValue = "The values of the coap_flag are: ";

//Loop through the nodes in the obj set
for (i=0; i< obj.length ; i++){
//set the currentElement to the 1st child node
currentElement = obj.item(i);
//Check to see if it is an applicant node
if (currentElement.name == "applicant"){
  //It is an applican, now find the coap_flag node value and write it to the text field
  TextField1.rawValue += "\n" + xfa.resolveNode("xfa.datasets.data.root.applicant[" + i + "]").coap_flag.value;
}
}

In all my examples I always create an object then check the length of the object. I do not know why but it does work.

Paul

Avatar

Former Community Member

ffor E.g

<Root >

   <Child>

      <Nod1>

      <Nod1>    

   </child>

   <Child>

      <Nod1>

      <Nod1>    

   </child>

</Root>

Now we can use tthe above code like

xfa.datsets.data.Root.nodes

then it will return the length - 2

But now again i  want to trace last node. Here <nod1> and <nod1>.

How to get the nod1 tag or how to find the length of the <child> tag .

Advance thanks .

Avatar

Level 10

Try like below..

You should be able to go down one level by using nodes.item.

xfa.datsets.data.Root.nodes.item(0).value

xfa.datsets.data.Root.nodes.item(1).value

Thanks

Srini

Avatar

Former Community Member

srini ,

can you please clear this one .

Based on tthe our scenarion ,

xfa.datsets.data.Root.nodes.item(0).value

what is the result of this code .

I need to get the child node of <child> tag .

Avatar

Former Community Member

Hi,

xfa.datsets.data.Root.nodes.item(0).value

here instead of value should be name to get the tag name .

Thanks .

Avatar

Correct answer by
Level 10

Yes you need to use the name instead of value to get the tag name..

     xfa.datsets.data.Root.nodes.item(0).name

Thanks

Srini