XPath kullanarak belirli bir attribute’a sahip node’u bulmak

Elimizde kullanıcıların olduğu bir XML dosyası olduğunu ve ID’si 4 olan kullanıcıyı bulmak istediğinizi düşünelim. XPath sorgunuz aşağıdakine benzer bir şekilde olmalıdır.

<kullanicilar>
    <kullanici id="1" isim="Ahmet" />
    <kullanici id="2" isim="Mehmet" />
    <kullanici id="3" isim="Ali" />
    <kullanici id="4" isim="Coskun" />
</kullanicilar>

XmlDocument m_XmlDocument = new XmlDocument();
m_XmlDocument.Load("~/App_Data/data.xml");

XmlNode node = m_XmlDocument.SelectSingleNode( "//kullanicilar/kullanici[@id='4']" );

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.