zoukankan      html  css  js  c++  java
  • 深入浅出InfoPath——操作InfoPath元素

    原理:InfoPath表单作为模板来定义Item中xml数据文件的格式和资源,那么我们在操纵InfoPath数据就等于是操作xml数据文件。

    1. 查询InfoPath表单元素
    2. 增加InfoPath表单元素

    先看下普通的XML中使用XPath进行查询的例子

    1. 删除InfoPath表单元素

    这里我们以复杂的Repeating Table为例

    下面的代码是通过按钮遍历查找Repeating Table中的某域为空的行,并删除一行(多行的情况请参考)。

    public void btnDeleteBlankRS_Clicked(object sender, ClickedEventArgs e)
    {
    //Create an XmlNamespaceManager for ease of referencing namespaces
    XmlNamespaceManager ns = this.NamespaceManager;

    //Create an XPathNavigator object for the main data source
    XPathNavigator xnMain = this.MainDataSource.CreateNavigator();

    //Create an XPathNodeIterator object for the repeating table so we can loop thru all the rows in the repeating table
    XPathNodeIterator xiRepeatingTable = xnMain.Select("/my:myFields/my:gpRepeatingTable/my:gpRepeatingTableRow", ns);

    //Loop thru all repeating table rows
    while (xiRepeatingTable.MoveNext())
    {
    //Create an XPathNodeIterator object for the repeating section nodes within the repeating table
    XPathNodeIterator xiRepeatingSection = xiRepeatingTable.Current.Select("my:gpRepeatingSection/my:gpRepeatingSectionRow", ns);

    //Loop thru the repeating sections within the current repeating table row
    while (xiRepeatingSection.MoveNext())
    {
    //Create an XPathNavigator object for one of the fields within the Repeating Section
    //NOTE: You may need to check more than one field to determine if the repeating section should be removed
    XPathNavigator xnRepeatingSectionField = xiRepeatingSection.Current.SelectSingleNode("my:field3", ns);

    //See if the field in the repeating section is empty
    if (xnRepeatingSectionField.Value == string.Empty)
    {
    //If so, delete the current repeating section
    xiRepeatingSection.Current.DeleteSelf();
    }
    }
    }
    }

    string name = "User2";
    string game = "Cube";
    XmlNode node
    = doc.SelectSingleNode(String.Format("/players/player[name='{0}' and game='{1}']", name, game));
    node.ParentNode.RemoveChild(node);

    或者

    String aaa = "/players/player[name='"+user+"' and game='"+game+"']";
    XmlNode node
    = docc.SelectSingleNode(aaa);
  • 相关阅读:
    1030 完美数列 (25 分)
    1029 旧键盘 (20 分)
    数据库命令失败原因汇总
    代码有中文括号,导致错误
    win10笔记本触控板使用指南
    (已解决)vsC#控制台应用添加System.Windows.Forms引用失败(精通C#)
    ildasm中Ctrl+M闪退的问题(已解决, 精通C# 15.1)
    C#控制台应用(.NET Core)添加System.Windows.Forms失败(已解决)
    知识点_指针_增加对指针的理解
    自己写出的Bug_应是%f却写成%d
  • 原文地址:https://www.cnblogs.com/mingle/p/InfoPath_xml_element.html
Copyright © 2011-2022 走看看