找到值后读取属性名称 [英] Reading attribute name after I find value

查看:66
本文介绍了找到值后读取属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读取一个xml文件,用于更新我们的活动目录.此文件已带有数据元素的标签已更改,需要更新.见下文

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

<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>



我可以轻松找到已更改的新值.在这种情况下,杰夫·贝克".我遇到的问题是在找到新值之后,我需要找到它是什么数据元素,在本例中为"manager".然后,我需要获取employeeID才能在AD中应用它.

谢谢

更新:

在阅读您的提示之前,我已经走近了.这是我到目前为止的内容:



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 />");
                                            
                }
            }



有了这个,我就能得到改变的值.它是什么属性,以及它是旧值还是新值(xdiff:oldValue).我现在的问题是移回节点的父节点以获取employeeID的值.

我已经尝试过MoveToAttribute("employeeID"," urn:com .....),但是它没有用.除非我语法错误.我已经尝试了几次在该方法中没有运气的情况下调用属性的方法.我在调用MoveToParent 2x之后调用了此方法,以到达顶部.


谢谢



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

推荐答案

您所说的数据元素"称为"XML属性".这些信息应该可以帮助您找到正在使用的XML类中找到该节点的方法.

(有几个设计用于XML的类.我不想为它们中的每一个提供帮助.我建议您根据自己的提示进行操作-这很容易.如果您仍然遇到一个问题,问题,请不要告诉我们您要使用什么类:显示一段看起来有问题的代码.)

—SA
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


通过使用此功能,我将其弄清楚了:我将其放置在以下行之后:
navResult.MoveToNextAttribute();



Thanks I figured it out by using this: I placed this after the following line:
navResult.MoveToNextAttribute();



navResult.MoveToParent();
                    navResult.MoveToParent();

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

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

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

                       navResult.MoveToParent();




然后,这给了我navResult.Value中的值.

再次感谢!




This then gave me my value in navResult.Value.

Thanks again!


这篇关于找到值后读取属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆