XPATH to repeating sect. entry via attr value? - InfoPath Dev
in

InfoPath Dev

XPATH to repeating sect. entry via attr value?

Last post 12-16-2005 12:35 PM by jeankap. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 12-16-2005 11:05 AM

    XPATH to repeating sect. entry via attr value?

    I've been fighting with this for a couple of days and cannot see the forest through the trees...

    I have a view that contains a single repeating section. New sections should be inserted or deleted based on checkbox values on other views. When a box is checked and a section inserted, I am using VB.net to set a "context" attribute on the repeating section to a value corresponding to the checkbox that spawned the insertion, and displaying the value in the section entry via an expression box control.

    Here's the repeating section data source tree:

    my:Root
    ... my:DesignSurvey
    .... my:Divisions
    ..... my:Opener
    ...... my:OpenerEntry (this repeats)

    my:OpenerEntry has a series of boolean attributes (more checkboxes) and one text attribute, my:Context, to keep track of which checkbox from the other view spawned the insertion of whichever specific entry.

    I've got the first part working - that is, the part where you check a box, and the onAfterChange event walks the dom and inserts a new repeating section, and then sets the context attribute:

    <InfoPathEventHandler(MatchPath:="/my:XPF/my:DesignSurvey/my:Divisions/my:Part/@my:PartOpener", EventType:=InfoPathEventType.OnAfterChange)> _
    Public Sub PartOpener_attr_OnAfterChange(ByVal e As DataDOMEvent)
    ' Write code here to restore the global state.

    If (e.IsUndoRedo) Then
    ' An undo or redo operation has occurred and the DOM is read-only.
    Return

    ElseIf (Not (e.Site Is e.Parent)) Then
    Return

    ElseIf ("Insert" <> e.Operation) Then
    Return

    End If

    'A field change has occurred and the DOM is writable. Write code here to respond
    'to the changes.
    Dim domDoc As IXMLDOMDocument = thisXDocument.DOM

    If e.Source.text = "1" Then

    Dim oTemplateGrp As IXMLDOMElement = domDoc.selectSingleNode("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry")

    Dim oTemplateNode As IXMLDOMElement = oTemplateGrp.cloneNode(True)

    domDoc.selectSingleNode("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener").appendChild(oTemplateNode)

    Dim chkExpression As IXMLDOMAttribute = domDoc.selectSingleNode("my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry/@my:Context")

    If chkExpression.value = "" Then
    Dim parentOpener As IXMLDOMElement = domDoc.selectSingleNode("my:XPF/my:DesignSurvey/my:Divisions/my:Opener")

    parentOpener.removeChild(oTemplateGrp)
    End If

    Dim contextNode As IXMLDOMElement = domDoc.selectSingleNode("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry")

    contextNode.setAttribute("my:Context", "Part")

    However, I have not been able to figure out how to navigate back to the correct repeating section if I go back to the view where I originally checked the box to insert the entry and uncheck the box... I thought I could do this by checking the context attribute value, but found that whatever value assigned to the context attribute from the last checkbox entry appears to have been reassigned to the context attribute in all of the entries despite the persistence of the correct text in the expression box in the view...

    I checked this via the second part of the code shown above:

    ElseIf e.Source.text = "0" Then

    thisXDocument.UI.Alert(e.Source.text)

    Dim nodeList As DOMNodeList = domDoc.selectNodes("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry")

    thisXDocument.UI.Alert(nodeList.length)

    Dim node As IXMLDOMNode

    Dim contextNode As IXMLDOMAttribute = domDoc.selectSingleNode("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry/@my:Context")

    Dim attrValue As String = contextNode.text

    For Each node In nodeList
    thisXDocument.UI.Alert(attrValue)
    Next
    End If
    Return

    End Sub

    So for instance, if I check boxes to insert a new repeating section for Appendix, Part, Chapter, and Box, in that order, I get 4 repeating sections, but when I try to display the values of the context attr in a UI.alert, I get whatever value corresponds to the last checkbox checked (in this case, box) 4 times - which means I cannot actually get back to the entry that was originally spawned by the checkbox to remove the node.

    Any ideas? Am I crossing my XPath apples and oranges and winding up with grapes? I'm happy to provide more information if this is not enough to start with.

    Thanks,
    Jean K.

  • 12-16-2005 12:05 PM In reply to

    Re: XPATH to repeating sect. entry via attr value?

    Change this:

    Dim contextNode As IXMLDOMAttribute = domDoc.selectSingleNode("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry/@my:Context")

    Dim attrValue As String = contextNode.text

    For Each node In nodeList
    thisXDocument.UI.Alert(attrValue)
    Next

    To This:

    For Each node In nodeList
    thisXDocument.UI.Alert( node.selectSingleNode( "@my:Context" ).text )
    Next node


    Sorry, if this isn't quite the right syntax - I don't do VB. Anyway, you are pulling the Context from ONE node and then repeating it for however many totaly entries there are. You need to access internal nodes within the loop, not outside and expect it to "magically update".

    Hope this helps!

    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-16-2005 12:35 PM In reply to

    Re: XPATH to repeating sect. entry via attr value?

    Oh yeah! That helps considerably. I did have some kind of XPATH /DOM thing within the For each at one point, but that wasn't working for me either...

    Now I just gotta figure out how to conditionally get rid of the sections (which should be much easier that I can actually get to those context values...)

    Thanks!

    quote:
    Originally posted by MFaus

    Change this:

    Dim contextNode As IXMLDOMAttribute = domDoc.selectSingleNode("/my:XPF/my:DesignSurvey/my:Divisions/my:Opener/my:OpenerEntry/@my:Context")

    Dim attrValue As String = contextNode.text

    For Each node In nodeList
    thisXDocument.UI.Alert(attrValue)
    Next

    To This:

    For Each node In nodeList
    thisXDocument.UI.Alert( node.selectSingleNode( "@my:Context" ).text )
    Next node


    Sorry, if this isn't quite the right syntax - I don't do VB. Anyway, you are pulling the Context from ONE node and then repeating it for however many totaly entries there are. You need to access internal nodes within the loop, not outside and expect it to "magically update".

    Hope this helps!

    ---------------
    Matt Faus
    InfoPath Dev Texas


Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.