Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9161813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:03:32+00:00 2026-06-17T14:03:32+00:00

I have the following XDocument called XDoc : <?xml version=1.0 encoding=utf-8?> <DatabaseList> <Database DatabaseName=c2501_data>

  • 0

I have the following XDocument called XDoc:

<?xml version="1.0" encoding="utf-8"?>
   <DatabaseList>
      <Database DatabaseName="c2501_data">
      <Plugin PluginName="FooPlugin" LastRun="1/21/2013 3:22:08 PM" />
      <Plugin PluginName="SpecialPlugin" LastRun="2013-01-21T15:22:09.3791103-05:00" />
      <Plugin PluginName="BarPlugin" LastRun="2013-01-21T15:23:13.0964814-05:00" />
   </Database>
</DatabaseList>

I’m writing a program that searches to see when the last time a plugin was run on a database, if at all. I use the following two pieces of code to figure out if an entry exists for a plugin on a database:

        var h = (from el in XDoc.Root.Elements("Database")
                 where el.Element("Plugin").Attribute("PluginName").Value=="FooPlugin" 
                 && el.Attribute("DatabaseName").Value=="c2501_data"
                 select el.Element("Plugin"));

        var e = (from el in XDoc.Root.Elements("Database")
                 where el.Element("Plugin").Attribute("PluginName").Value=="BarPlugin"
                 && el.Attribute("DatabaseName").Value == "c2501_data"
                 select el.Element("Plugin"));


        if ((from el in XDoc.Root.Elements("Database")
             where el.Element("Plugin").Attribute("PluginName").Value == "BarPlugin"
             && el.Attribute("DatabaseName").Value == "c2501_data"
             select el.Element("Plugin")).Count() == 0)
        {
            XElement SpecialPlugin = new XElement("Plugin",
                new XAttribute("PluginName", "BarPlugin"),
                new XAttribute("LastRun", DateTime.Now));

            var CurNode = from node in XDoc.Root.Elements("Database")
                          where (string)node.Attribute("DatabaseName").Value == "c2501_data"
                          select node;

            foreach (var node in CurNode)
                node.Add(SpecialPlugin);

            XDoc.Save(RuntimesPath);
            //XDoc.Root.Elements("Database").Attribute("DatabaseName").
        }

The problem that I’m having is that even though there is clearly an entry for BarPlugin, the count will always return 0 and e will always be unable to create an enumberable. Can anyone explain to me why this might be? FooPlugin always works correctly and returns the Plugin information for h.

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:03:33+00:00Added an answer on June 17, 2026 at 2:03 pm

    You’re selecting a Database element where it contains a child element called Plugin with a given name. Since you have only one Database element, you’re getting the same outer element each time. You then take that database element and return the first Plugin child, which will always be Foo, in this case. You need to find the appropriate Database element and then query through each of the child elements so you can return them:

    public static XElement GetPlugin(XDocument XDoc, string databaseName, string pluginName)
    {
        var h = from database in XDoc.Root.Elements("Database")
                where database.Attribute("DatabaseName").Value == databaseName
                from plugin in database.Elements("Plugin")
                where plugin.Attribute("PluginName").Value == pluginName
                select plugin;
    
        return h.FirstOrDefault();
    }
    

    Or, if you prefer, in method syntax:

    var q = XDoc.Root.Elements("Database")
        .Where(db => db.Attribute("DatabaseName").Value == databaseName)
        .SelectMany(db => db.Elements("Plugin"))
        .Where(plugin => plugin.Attribute("PluginName").Value == pluginName);
    
    return q.FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following xml code in a document called note.xml <?xml version="1.0" encoding="ISO-8859-1"?>
I have an xml (called xdoc) file like the following: <Root> <ItemContainer> <Item> <Item>
Assuming I have a xdocument called xd, with the following xml already created. <Alert>
If I have the following xml: XDocument xDocument = new XDocument( new XElement(RootElement, new
I have the following XML LINQ query from my XDocument. var totals = (from
I have the following XDocument: <SomeDoc Id=73 Protocol=rahrah xmlns=http://schemas.company.com/rah/rah2/2005/> <Prop1>11111</Prop1> <Prop2>77777</Prop2> <Prop3>88888</Prop3> </SomeDoc> And
I have the following code : XDocument xResponse = XDocument.Parse(strXMLResponse); var vMyData = from
I have the following document in a couchdb database: { _id: 000013a7-4df6-403b-952c-ed767b61554a, _rev: 1-54dc1794443105e9d16ba71531dd2850,
I have the following xml document, I need an xquery expression to know how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.