Manipulating XML using C# - InfoPath Dev
in

InfoPath Dev

Manipulating XML using C#

Last post 10-14-2005 01:03 AM by DavidCrabbe. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-12-2005 02:39 AM

    Manipulating XML using C#

    I have a number of optional sections in my form that are, by default, not included in the form's data structure until the user checks a checkbox and the section is included using thisXDocument.View.ExecuteAction( xOptional::insert, <xPath> ). When the user unchecks the checkbox, the group is removed using xOptional::remove.

    Note: I'm forced to use conditional presence as the sections contain 'cannot be blank' fields that would otherwise cause the validation to fail if they were merely hidden by conditional formatting.

    This works fine if the section to be inserted is in the same view as the checkbox which controls its insertion. However, I have a group which should only appear on an 'approval' view that I only want to include if the user selects a checkbox on the 'request' view.

    Using View.ExecuteAction doesn't work as the optional section is on a different view. I can create an empty optional section on the 'request' view that inserts the group, however this is a messy workaround and if I hide it using conditional formatting I can't remove it using xOptional::remove when the user unchecks the option.

    Can anyone advise me as to how I can add and remove groups from my XML document using C# code that doesn't use View.Execute action?

    I've read that the DOM offers this facility but I'm not at all familiar with it and a brief flirtation resulted a flurry of errors.

    I'd really appreciate some help with this query as I'm kinda stuck at the moment...

    David.
  • 10-12-2005 02:52 AM In reply to

    Re: Manipulating XML using C#

    I should point out that XML that I'm trying to insert (an InfoPath Group) is defined within my InfoPath data source (.xsd) and all I wish to do is include or exclude it based on a user selection.

    I don't want to have to explicitly define the XML data structure in code.

    Thanks!
  • 10-12-2005 07:00 AM In reply to

    Re: Manipulating XML using C#

    Instead of inserting/removing sections of XML with "Cannot be blank" fields in them, why don't you just take off the "Cannot be blank" flag, use conditional formatting, and do data validation via code?

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-12-2005 08:01 PM In reply to

    Re: Manipulating XML using C#

    Hi Matt,

    Thanks for the suggestion, I could do that however:
    a) Validation would be painful, I've got 50+ fields to check, and how do I indicate which fields cannot be blank other than hardcoding?
    b) I'd lose the natty little red star next to the mandatory fields which inform the user that the they cannot be blank.

    I can't help but feel there must be a better option, one that actually uses the XML schema and InfoPath built-in functionality to indicate 'cannot be blank'.

    David.
  • 10-14-2005 01:03 AM In reply to

    Re: Manipulating XML using C#

    I have come up with an answer of sorts, and I'll post it for review:

    I've used the OnSwitchView event to check for when the 'approval' view is selected. For each of the optional sections I wish to include I test the checkbox value, set in the 'request' view, and use xOptional::insert to add it in if required.

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