Getting the node type, ie: Group or Field. - InfoPath Dev
in

InfoPath Dev

Getting the node type, ie: Group or Field.

Last post 03-03-2006 12:48 PM by Agni Jonnalagadda. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-26-2006 01:23 AM

    • rjohnson
    • Top 500 Contributor
    • Joined on 09-02-2005
    • Australia
    • Posts 28

    Getting the node type, ie: Group or Field.

    Hi all,

    I was wondering if there was a way of determining whether a given node is a 'Group', or a 'Field', via JScript code.

    I've tried several ways to get that information, but none have succeeded.
    Since I can actually see whether it is a Group or Field in the InfoPath GUI, I would figure there is a way of getting that information with code.

    I tried:

    var Node = XDocument.DOM.selectSingleNode("/my:myFields");
    which sets Node to the group in the dataSource, and then I try to get its Type with:
    XDocument.UI.Alert( Node.nodeType )
    but this returns the value 1.

    Likewise, if I access a field in the dataSource
    var Node = XDocument.DOM.selectSingleNode("/my:myFields/my:myField1");
    and get its nodeType, it returns 1 as well.

    I believe the 1 that is being returned, actually represents that it is an element,
    but is there a way of knowing whether a node is set to a field or group?

    Any help would be welcomed,
    Thanks,

    - Reg.
  • 03-02-2006 09:49 PM In reply to

    Re: Getting the node type, ie: Group or Field.

    Hi,
    For given node,check childNodes.length>0,
    If it is, it will be group otherwise field.

    Thanks.
    K.Ramana Reddy / http://www.ggktech.com
    India.
  • 03-03-2006 05:57 AM In reply to

    • rjohnson
    • Top 500 Contributor
    • Joined on 09-02-2005
    • Australia
    • Posts 28

    Re: Getting the node type, ie: Group or Field.

    Hi K.Ramana,

    Thanks for your reply,

    However, I don't think that 'childNodes.length' can always guarantee that returning a 0, is always from a field.

    For example, I noticed that if the field is empty, it will return 0, but if the field contains a value, it will return 1.

    Contrary, if a "group" has no fields in it, it too will return 0.

    If you are able to, can you clarify if these notions are correct.

    Thanks,

    - Reg.
  • 03-03-2006 11:09 AM In reply to

    Re: Getting the node type, ie: Group or Field.

    Hi Reg,

    You are correct reg, i saw same thing what you mentioned,
    i tried so many things to get correct result, but i did not get it,

    Thanks.
    K.Ramana Reddy / http://www.ggktech.com
    India.
  • 03-03-2006 12:48 PM In reply to

    Re: Getting the node type, ie: Group or Field.

    Hi,
    You can get the child nodes using the "child::node()" Xpath.
    node.selectNodes("child::node()").length should give you the length of the child nodes.
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.