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.
- Query infopath form elements
- Add infopath form elements
First, let's look at the example of using XPath for queries in common XML.
- 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 );