Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPathNodeIterator move.next method is not looping through each single value???

Status
Not open for further replies.
Feb 21, 2013
6
US
Code:
//update list item

 string siteUrl = [URL unfurl="true"]http://sp-app/dev;[/URL]
ClientContext clientContext = new ClientContext(siteUrl);

 list oList = clientContext.Web.Lists.GetByTitle("Item Inventory");

PathNavigator root = MainDataSource.CreateNavigator();

 

XPathNodeIterator iter = root.Select("/my:myFields/my:group1", NamespaceManager);

 

while (iter.MoveNext())

 {

string value = iter.Current.Value;

 

int id;

 

Int32.TryParse(value, out id);



ListItem oListItem = oList.GetItemById(id);



 oListItem[

"Title"] = field1;

 oListItem.Update();

I figured out what is wrong but don't know how to fix it. When I select more than one checkboxes, the xPathNodeiterator concates all the values together instead of looping through each value individually. For instance,

select check box 1

select Checkbox 2

value = 12 my goal is to have a loop

value =1 than

value = 2.

select checkbox 1

value = 1

Can somone tell me why this isnt looping thorugh each single value? and why is it appending them all into one value? this will solve the problem. thanks
 
Is group1 the GroupBox that contains your checkboxes? If it is, you should be selecting by checkbox instead.
 
i tried. that gives me another error
Code:
    //create a xPathnav
            XPathNavigator listBox = MainDataSource.CreateNavigator();

            //create a xPathIterator
            XPathNodeIterator iter = listBox.Select("/my:myFields/my:group1/my:field3", NamespaceManager);

         
            //foreach (XPathNavigator iters in iter)
                //Console.WriteLine(iters.Value);


            while (iter.MoveNext())
            {
                //string value = iters.Current.Value;
                //XPathNodeIterator newIter = iter.Current.SelectDescendants(XPathNodeType.Element, false);
         
                    string value = iter.Current.Value;
                    string siteUrl = "[URL unfurl="true"]http://sp-app/dev";[/URL]
                    ClientContext clientContext = new ClientContext(siteUrl);
                    List oList = clientContext.Web.Lists.GetByTitle("Item Inventory");

                    ListItem oListItem = oList.GetItemById(value);

                    oListItem["Title"] = "hahaha";
                    oListItem.Update();
                    clientContext.ExecuteQuery();
         
                   }

the error is on this line
ListItem oListItem = oList.GetItemById(value);--------{"The 'sId' argument is invalid."} The value is nothing.
 
Have you stepped through this code with a debugger? It sounds like the string "value" doesn't have the content you are expecting.
 
I understand that much PDMAdmin. That what i said by the value is nothing. When I use this XPathNodeIterator iter = listBox.Select("/my:myFields/my:group1/my:field3", NamespaceManager);
, I get nothing for the value.

When I use this XPathNodeIterator iter = root.Select("/my:myFields/my:group1", NamespaceManager, i get the group of elements and therfore it concates all the values together and I thought the iter.move method would iterate each single value but it doesnt. I just do not know what the syntax or code is to select each single checkbox value and loop through each inidvidually.
 
Code:
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.27" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Users\spadmin\AppData\Local\Microsoft\InfoPath\Designer3\c599af3827794388\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?><my:myFields xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:pc="[URL unfurl="true"]http://schemas.microsoft.com/office/infopath/2007/PartnerControls"[/URL] xmlns:ma="[URL unfurl="true"]http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes"[/URL] xmlns:d="[URL unfurl="true"]http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields"[/URL] xmlns:q="[URL unfurl="true"]http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields"[/URL] xmlns:dfs="[URL unfurl="true"]http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"[/URL] xmlns:dms="[URL unfurl="true"]http://schemas.microsoft.com/office/2009/documentManagement/types"[/URL] xmlns:my="[URL unfurl="true"]http://schemas.microsoft.com/office/infopath/2003/myXSD/2013-02-13T18:23:25"[/URL] xmlns:xd="[URL unfurl="true"]http://schemas.microsoft.com/office/infopath/2003"[/URL] xml:lang="en-us">
	<my:field1></my:field1>
	<my:field2></my:field2>
	<my:group1>
		<my:field3></my:field3>
	</my:group1>
	<my:txtEval></my:txtEval>
	<my:group2>
		<my:group3>
			<my:field5></my:field5>
		</my:group3>
	</my:group2>
	<my:selectAll>false</my:selectAll>
</my:myFields>
 
Your XML selection looks okay to me. Without seeing more of your code, it's hard for me to make a specific recommendation. One idea that comes to mind is to go back to selecting by group, getting the "value=12" scenario you were seeing before. You could then do something like this:

if(value.Contains("1"))
// Process checkbox 1
if(value.Contains("2"))
// Process checkbox 2
 
I have about 40 checkboxes. That would be to many if statements. what other code do you need? Can you help me revise this to use For Each statement loop. instead of iter.movenext. Thats another way it may work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top