Solved

Difficult one...Active Directory + XML...

Posted on 2007-03-20
5
899 Views
Last Modified: 2013-11-07
Hi,
I read from AD and The CN (commonName) has a property that if i get its value
i get it in XML format.
I'm lookin for some way to enter the nodes and retrieve the value.
My code (to get other properties valus) are:
-------------------------------------------------------------
DirectoryEntry root = new DirectoryEntry(
              "LDAP://10.1.1.1/DC=Internet,DC=Test",
              "User", "Password", AuthenticationTypes.ServerBind);

            DirectorySearcher search = new DirectorySearcher(root);
            search.Filter = "(&(objectClass=user))";
            search.PropertiesToLoad.Add("ID");
            SearchResult result;
            SearchResultCollection resultCol = search.FindAll();
            string[] allUsers = new string[resultCol.Count];
            if (resultCol != null)
            {
                     for (int counter = 0; counter < resultCol.Count; counter++)
                {
                    result = resultCol[counter];
                    if (result.Properties.Contains("ID"))
                    {
                        allUsers[counter] = ((string)result.Properties["ID"][0]);                                      
                        Console.WriteLine("Value : " + allUsers[counter]);
                     }
                }
             }
--------------------------------------------------------------------------
and i get all the values of the ID propert.
Now, there is a property - which its value is in XML :
<names>
   <way> SMS </way>
</names>
The property name is : " Delivery ".
(if i try to retrieve Delivery value - i get an XML result.
I need to get only the value ---  SMS
Is it possible?
Thanks
0
Comment
Question by:udir
  • 4
5 Comments
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 500 total points
ID: 18759644
Does it always return valid XML?  And does it return it as a string?
If so, something like:

    // ...
    object deliveryValue = result.Properties["Delivery"];
    string wayValue = null;
    if (deliveryValue != null)
    {
        XmlDocument xml = new XmlDocument();
        xml.LoadXml(deliveryValue.ToString());
        XmlNode wayNode = xml.SelectSingleNode("//names/way");
        if (wayNode != null) wayValue = wayNode.Value;
    }
    // ...

HTH

J.
0
 
LVL 1

Author Comment

by:udir
ID: 18762300
Hi,
Thanks for the reply.
It looks like the right way  (:
the problem is that i get nulls.
(i also changed the line to - object deliveryValue = ((string)result.Properties["ladpcInfodelivery"][0]);  )

Maybe the single Node Method has a wrong path?
the real pass that i wrote in the code in order to get to the Node is : (above i just gave an example)
-------------------------------------------------------------------------------
XmlNode Nodename = xml.SelectSingleNode("//ArrayofApp/App/Name/Modules/Module/Name/DeliveryMethods/DeliveryMethod/Name");
-------------------------------------------------------------------------------
and the XML looks like this (when i get the property Value)
Value : <ArrayOfApp>
            <App>
                <Name>EVoucher</Name>
                <Modules>
                        <Module>
                                <Name>UpdateDelivery</Name>
                                <DeliveryMethods>
                                        <DeliveryMethod>
                                                <Name>HardCopy</Name>
                                        </DeliveryMethod>
                                              <DeliveryMethod>
                                                   <Name>Email</Name>
                                             </DeliveryMethod>
                                      </DeliveryMethods>
                        </Module>
                </Modules>
          </App>
    </ArrayOfApp>

Am i missing somthing?
0
 
LVL 1

Author Comment

by:udir
ID: 18762303
Oh, and i need to get the only the Name value - " EMail " 
0
 
LVL 1

Author Comment

by:udir
ID: 18762624
or SMS
0
 
LVL 1

Author Comment

by:udir
ID: 18763015
OK, let me sumerize the problem so far:
1)  If i write as you wrote :  object deliveryValue = result.Properties["Delivery"];
      i get an error :  Data at the root level is invalid. Line 1, position 1
      at the line :  xml.LoadXml(deliveryValue.ToString());
 (which i understand is becuase the property return not a valid XML but a string (as you can see in the file above - it really begins with " Value : <ArrayOfApp>...........

2)  If i write as I wrote :  object deliveryValue = ((string)result.Properties["ladpcInfodelivery"][0]);
      i get nulls - " wayNode " is null (maybe somthing with the root)

How can it be solved (dosn't metter which way)
Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question