Results 1 to 3 of 3

Thread: [RESOLVED] Help with XML query

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Resolved [RESOLVED] Help with XML query

    hi guys! currently i have the code below which query something from Sharepoint List Service but how will I modify it in such a way that it will query all rows from field2 with value in other words i want to get all those rows in field2 which has value.

    Code:
    Web_Reference_Folder_Name.Lists listService = new Web_Reference_Folder_Name.Lists();
    listService.Credentials= System.Net.CredentialCache.DefaultCredentials;
    
    XmlDocument xmlDoc = new System.Xml.XmlDocument();
    
    XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
    XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
    XmlNode ndQueryOptions = xmlDoc.CreateNode(XmlNodeType.Element,"QueryOptions","");
    
    ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" + 
        "<DateInUtc>TRUE</DateInUtc>";
    ndViewFields.InnerXml = "<FieldRef Name='Field1' /><FieldRef Name='Field2'/>";
    ndQuery.InnerXml = "<Where><And><Gt><FieldRef Name='Field1'/>" + 
        "<Value Type='Number'>5000</Value></Gt><Gt><FieldRef Name='Field2'/>" + 
        "<Value Type='DateTime'>2003-07-03T00:00:00</Value></Gt></And></Where>";
    try
    {
        XmlNode ndListItems = listService.GetListItems("List_Name", null, ndQuery, 
            ndViewFields, null, ndQueryOptions);
        MessageBox.Show(ndListItems.OuterXml);
    }
    
    catch (System.Web.Services.Protocols.SoapException ex)
    {
        MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText + 
             "\nStackTrace:\n" + ex.StackTrace);
    }

  2. #2

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: Help with XML query

    My Solution:
    Code:
    ndQuery.InnerXml = "<Where><IsNotNull><fieldRef Name='field2'/></IsNotNull></Where>";

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Help with XML query

    Use the XMLDocument object's SelectNodes() method. You can specify an XPath string in it:

    /something/field1/field2[exists(field2/text())]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width