Select specific node value from XML using C# in ASP.Net

Last Reply 7 months ago By dharmendr

Posted 7 months ago

Hello all,

I created an XML document. I kind of looked at the C# settings because this is going to be a custom config script for my program. I need to have it in a specific directory which I already have, but now I am trying to get the correct nodes data. How can I choose a specific node value using XML?

Here is what I have.

I have 1 node with multiple values (paths) and another node that has the same parent node as a different I want the second ones value.

I want the second <DataBase> value. ‘PDMDataBaseName’ and all the Paths in <FilePaths>

    <UserProfile Name="UserPlus" Type="System.Boolean" Scope="User">
      <Value Profile="(Default)">True</Value>
    <DataBase Name="DataBaseName" Type="System.String" Scope="User">
      <Value Profile="(Default)">TRACKER </Value>
    <DBTable Name="FileTableName" Type="System.String" Scope="User">
      <Value Profile="(Default)">ScannedPDFtest</Value>
    <FilePaths Name="FileDirectories" Type="System.Collections.Specialized.StringCollection" Scope="User">
      <Path>\\file01\public1\Eng Files .pdf</Path>
    <DataBase Name="PDMDataBaseName" Type="System.String" Scope="User">
      <Value Profile="(Default)">TRACKER_TEST</Value>

Code to get userplus value 

var queryUser = from u in xml.Descendants("Settings")
                //where u.Element = "UserProfile"
                select u.Element("UserProfile").Value;
lblUserPlus.Text = queryUser.First();

others I been trying without luck

var queryFileTable = from ft in xml.Descendants("Settings")
                     select ft.Element("DBTable").Value;
lblFileTable.Text = queryFileTable.FirstOrDefault();

var queryFileDirs = from fd in xml.Descendants("Settings")
                    // where fd.Element("DBTable").Attribute("PDMTableName")
                    // select fd.Value;
                    select fd.Element("DBTable").Attribute("PDMTableName");
lblFileDirs.Text = queryFileDirs.ToString();



This question does not have replies that have been liked.