Question

<Default>
<SharepointContentType id="SharePointContentType">

<name id="Test1"
         DisplayName="TestOne"
         SharepointGroup="Test1SPGp">
    </name>

<name id="Test2"
         DisplayName="TestTwo"
          SharepointGroup="Test2SPGp">
    </name>
.
.
.
.

</SharepointContentType>
.
.
.
.
<Default>

For the above schema i want to descend as, find a node where id is SharePointContentType than find tag <name > where id is Test1(user defined) and than fetch the value for the the element SharepointGroup

e.g if user input is Test1 than out put should be Test1SPGp Kindly help i was trying to use linq and managed to code as below but could not succeed.

    XDocument xDoc = XDocument.Load(GetDefaultXMLFile());

    var feeds = from feed in xDoc.Descendants("name")
                where feed.Attribute("id").Equals("admin")
                select new
                {
                    fxfv = feed.Attribute("SharepointGroup").Value
                };
Was it helpful?

Solution

I think you have a mistake in where condition, see below:

feed.Attribute("id") returns XAttribute class so you can't use equals to compare to a string, but after Value property you can.

        var feeds = from feed in xDoc.Descendants("name")
                    where feed.Attribute("id").Value.Equals("Test1")
                    select new
                    {
                        fxfv = feed.Attribute("SharepointGroup").Value
                    };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top