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

  • Home
  • SEARCH
  • 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 989053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:43:50+00:00 2026-05-16T05:43:50+00:00

my xml is below: <Demo> <ClientCompanyId CompanyId=1> <MyMenu> <module MenuType=0 ModID=Mod1 ModuleID=1 Perm=False Text=Basic

  • 0

my xml is below:

<Demo>
    <ClientCompanyId CompanyId="1">
        <MyMenu>
            <module MenuType="0" ModID="Mod1" ModuleID="1" Perm="False" Text="Basic Settings">
                <menu MID="1-1" MenuDescription="Mod" MenuType="0" ModuleID="1" ParentID="Mod1" Perm="False" Text="Forms">
                    <Leaf LeafNode="true" MID="1-3" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-3" ParentID="1" Perm="False" TargetUrl="" Text="LookUp"/>
                    <submenu MID="1-4" MenuDescription="" MenuType="0" ModuleID="1" ParentID="1" Perm="False" Text="Bank Branch">
                        <Leaf LeafNode="true" MID="1-5" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-5" ParentID="4" Perm="False" TargetUrl="" Text="BO Category"/>
                    </submenu>
                </menu>
                <menu MID="1-2" MenuDescription="Mod" MenuType="0" ModuleID="1" ParentID="Mod1" Perm="False" Text="Reports">
                    <Leaf LeafNode="true" MID="1-6" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-6" ParentID="2" Perm="False" TargetUrl="" Text="Cheque Type"/>
                    <Leaf LeafNode="true" MID="1-7" MenuDescription="" MenuType="0" ModuleID="1" ModuleMenuID="1-7" ParentID="2" Perm="False" TargetUrl="" Text="Stock Exchange"/>
                </menu>
            </module>
        </MyMenu>
    </ClientCompanyId>
</Demo>

my linq syntax is below:

 XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");
 var q = from c in loaded.Descendants("module")
 where (int)c.Attribute("ModuleID") < 0
 select (string)c.Attribute("Text");

From the above xml file i want to get tag attributes values.

Text="Basic Settings" ModID="Mod1" ModuleID="1" MenuType="0" Perm="False"

From the above xml i want to get all tag attributes values .

How to get value from an xml file?

  • 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-05-16T05:43:51+00:00Added an answer on May 16, 2026 at 5:43 am

    Or you can in the last step cast to XElement and use whatever XElement has to offer:

    instead of var q:

    IEnumerable<XElement> q =from c in loaded.Descendants("module") 
                        where (int)c.Attribute("ModuleID").Value < 0 
                        select c;
    
    foreach(XElement e in q){
       string t = e.Attribute("Text").Value;
       // etc...
    }
    

    if you know one record is going to be return

    XElement q = (from c in loaded.Descendants("module") 
                        where (int)c.Attribute("ModuleID").Value < 0 
                        select c).First(); // one of many options to return a single record
    
    sring t = q.Attribute("Text").Value;
    // etc...
    

    UPDATE

    to make further queries to your result:

    IEnumarble<XElement> menus = q.Elements("menu");
    

    then loop foreach, you can use menuselement.Element("tag_name").Value to get string values of the nodes, or menuselement.Attribute("attr_name").Value to get attribute values, and you can further query with menuslement.Find or menuselement.Where or menuselement.Select and the options are really limitless… here is where you can learn more:
    http://msdn.microsoft.com/en-us/library/bb387065.aspx

    And here is MSDN’s how to query xml using linq:
    http://msdn.microsoft.com/en-us/library/bb943906.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume, you have the xml below. The goal is to group by FirstName
with the XML structure below: <root foo1=bar1 foo2=bar2 foo3=bar3> <foo1 foo1=bar1 /> <data> <foo1>bar1</foo1>
I have an xml file like below which I will use to set background
Hi I've parent pom.xml like below.. , say I've 4 modules currently.. But at
i want to insert iteration elements(Signal) according my requirement like below xml output. <?xml
I've seen (and done) data source configuration in two ways (the code below is
Hi I'm trying to get a variable value (ref within contractRef) in the xml
To be honest I didn't still used XML with jQuery. I have a little
I need to Convert my XML Data to an ADO RecordSet. I am able
I guess I'm pushing the boundaries of whats capable with LINQ to XML but

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.