Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
I am reading an xml file to use to update our active directory. This file already tags with data element has been changed that needs updating. See Below

XML
<ws:Worker xdiff:isDifferent="true">
- <ws:Personal>
  <ws:Employee_ID>5295</ws:Employee_ID>
  <ws:Name>John Doe</ws:Name>
  </ws:Personal>
- <ws:CoreInformation>
  <ws:Eligibility>true</ws:Eligibility>
  </ws:CoreInformation>
- <ws:Group name="WorkerTest1">
  <ws:Field name="displayName">John Doe</ws:Field>
  <ws:Field name="givenName">John</ws:Field>
  <ws:Field name="sn">Doe</ws:Field>
  <ws:Field name="mail">JDoe@aol.com</ws:Field>
  <ws:Field name="title">Programmer</ws:Field>
  <ws:Field name="employeeID">5295</ws:Field>
  <ws:Field name="manager" xdiff:oldValue="Eric Clapton">Jeff Beck</ws:Field>
  <ws:Field name="location">New York</ws:Field>
  </ws:Group>
  </ws:Worker>


I can easily find the new value that was changed. In this case "Jeff Beck". What I am having problems with is after I find the new value I need to find what data element it is, in this case "manager". Then I need to get the employeeID to apply it in AD.

Thanks

UPDATE:

I was able to get closer prior to reading your hint. This is what I have so far:

XPathDocument doc = new XPathDocument(@"C:\520110413.xml");
            
            XPathNavigator nav = doc.CreateNavigator();
            XmlNamespaceManager mgr = new XmlNamespaceManager(nav.NameTable);
                     
            mgr.AddNamespace("ws", "urn:com..........");
            mgr.AddNamespace("xdiff", "urn:com..........");

 
 XPathNodeIterator it = nav.Select("ws:Worker_Sync/ws:Worker/ws:Group/ws:Field[@xdiff:isAdded='true' or @xdiff:isDeleted='true' or @xdiff:oldValue]", mgr);           

            XPathNavigator navResult = it.Current;
            
while (it.MoveNext())
            {
                Response.Write(" result Value: " + navResult.Value  );
                if (navResult.HasAttributes)
                {
                    navResult.MoveToFirstAttribute();
                                      
                      Response.Write(" Field Name: " + navResult.Value );
                        navResult.MoveToNextAttribute();
                      Response.Write(" TYPE: " + navResult.Name + "<br />" + "<br />");
                                            
                }
            }


With this I am able to get the value that changed..What attribute it is..and if it was and old value or new (xdiff:oldValue). My problem now is moving back to the parent of the node to get the value of the employeeID.

I've tried MoveToAttribute("employeeID",""urn:com.........."), but it didn't work. Unless I have the syntax wrong. I've tried several ways of calling the attribute within that method with no luck. I called this after calling MoveToParent 2x, to get to the top.


Thanks
Posted
Updated 15-Apr-11 5:27am
v5

What you call "data element" is called "XML attribute". This information should help you to find the way to find this node in the XML class you're using.

(There are several classes designed to work with XML. I don't want to provide you help for each and every one of them. I suggest you do it by yourself using my hint — this is very easy. If you still face a problem, don't tell us what class you want to use: show a short piece of code which looks problematic.)

—SA
 
Share this answer
 
Comments
Espen Harlinn 14-Apr-11 16:42pm    
Good hint, my 5
Sergey Alexandrovich Kryukov 14-Apr-11 16:50pm    
Thank you, Espen.
--SA
swbo102 15-Apr-11 11:28am    
Thanks for the suggestion. I have updated my question to provide more information.
Thanks I figured it out by using this: I placed this after the following line:
navResult.MoveToNextAttribute();



C#
navResult.MoveToParent();
                    navResult.MoveToParent();

                   navResult.MoveToFirstChild();
                   navResult.MoveToNext();
                   navResult.MoveToFirstAttribute();

                       do
                       {
                           navResult.MoveToParent();
                           navResult.MoveToNext();
                           navResult.MoveToFirstAttribute();

                       }
                       while (navResult.Value != "employeeID");

                       navResult.MoveToParent();



This then gave me my value in navResult.Value.

Thanks again!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-Apr-11 17:00pm    
You're welcome.
If you find my Answer somehow useful, please formally accept it.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900