Results 1 to 3 of 3

Thread: [RESOLVED] Help with XML Document

  1. #1

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

    Resolved [RESOLVED] Help with XML Document

    Hi guys! Help please..I have a code below that retrieves Data from Sharepoint 2003 thru its Web Services which returns data as XML Document, and assigned that XML Document to ndEventsItems variable of type XmlNode
    Code:
            public XmlNode FuncGetEvents()
            {
    	    XmlNode ndEventsItems;
                try
                {
                    string DateToday = DateTime.Now.ToString("yyyy-MM-dd");
                    lstServiceEvents.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    lstServiceEvents.PreAuthenticate = true;
    
                    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", "");
    
                    ndQuery.InnerXml = "<Where>" +
                                       "<Geq><FieldRef Name='EventDate'/><Value Type='DateTime'>" + DateToday + "</Value></Geq>" +
                                       "</Where>";
    
                    ndEventsItems = lstServiceEvents.GetListItems("Events", null, ndQuery, null, null, ndQueryOptions);
                }
                catch (Exception ex)
                {
                    AlarmEventsEnable = false;
                    Common.LogException(ex, "FuncGetEvents");
                }
                return ndEventsItems;
            }
    The OuterXml Property of ndEventsItems variable could have a value somthing like below

    <listitems
    xmlns:s=\"uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882\"
    xmlns:dt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\"
    xmlns:rs=\"urn:schemas-microsoft-com:rowset\"
    xmlns:z=\"#RowsetSchema\"
    xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"
    >

    <rs:data ItemCount=\"2\">
    <z:row ows_fRecurrence=\"0\" ows_LinkTitle=\"BAC Meeting\" ows_EventDate=\"2007-08-15 09:00:00\" ows_Location=\"C. U. Del Rosario Hall B &amp; C Power Training Center Bldg.\" ows_Alarm=\"2007-08-14 16:45:00\" ows_AlarmMemberChoice=\"ALL\" ows_Attachments=\"0\" ows_Attachment=\", \" ows_Title=\"BAC Meeting\" ows_ID=\"106\" ows_owshiddenversion=\"8\" />
    <z:row ows_fRecurrence=\"0\" ows_LinkTitle=\"Test1\" ows_EventDate=\"2007-08-15 00:00:00\" ows_AlarmMemberChoice=\"ALL\" ows_Attachments=\"0\" ows_Attachment=\", \" ows_Title=\"Test1\" ows_ID=\"107\" ows_owshiddenversion=\"1\" />
    </rs:data>
    </listitems>

    My first question is it posible to Loop through the nodes or rows and check if the value of "ows_LinkTitle" Attribute is equal to "Test1" and if it matches the criteria that row or node will be deleted.

    My second question is, if first question is not posible, Is it posible to convert the ndEventsItems variable of type XmlNode to Dataset?

    Thanks in advance!
    Last edited by daimous; Aug 16th, 2007 at 02:49 AM.

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Help with XML Document

    You can find if you attribute has a certain value using the right XPath.

    /root/parentnode/nodetocheck[@attribute='attributevalue']

    If this returns a node, then your attribute and value exist, so you can do what you like to them.

  3. #3

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

    Re: Help with XML Document

    Problem Solved!...Just want to share...
    Solution for my Second question:
    Code:
            public DataSet FuncConvertToDataset(XmlNode xNode)
            {
                DataSet ds = new DataSet();            
                string tmp = string.Empty;
                if ((xNode != null) && xNode.InnerXml.Length > 0)
                {
                    XmlTextReader reader = new XmlTextReader(xNode.OuterXml, XmlNodeType.Element, null);
                    ds.ReadXml(reader);
                }
                return ds;            
            }
    If you have Comments or Better suggestion please dont hesitate to post it here. Thanks a lot guys for the inputs...

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