SharePoint [simple infopath]-operate the infopath Element

Source: Internet
Author: User

Principle: infopath forms are used as templates to define the formats and resources of XML data files in items. Therefore, manipulating infopath data is equivalent to operating XML data files.

  1. Query infopath form elements
  2. Add infopath form elements

First, let's look at the example of using XPath for queries in common XML.

  1. Delete infopath form elements

Here we take the complex repeating table as an example.

The following code uses a button to traverse and search for rows with an empty field in the repeating table and delete a row (for details about multiple rows, see ).

Publicvoid btndeleteblkrs_clicked (Object sender, clickedeventargs E)
{
// Create an xmlnamespacemanager for example 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 shocould 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 );

Or

String AAA = "/players/player [name = '" + User + "' and game = '" + Game + "']";
Xmlnode node = docc. selectsinglenode (AAA );

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.