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 7796071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:15:34+00:00 2026-06-01T23:15:34+00:00

say, i have such xml file: <?xml version=1.0?> <catalog> <title>My book catalog</title> <link>http://example.com/catalog</link> <book

  • 0

say, i have such xml file:

<?xml version="1.0"?>
<catalog>
   <title>My book catalog</title>
   <link>http://example.com/catalog</link>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
</catalog>

in the end it’s needed to get object, which i can use as follows:

xml.title    //must return "My book catalog"
xml.link     //must return "http://example.com/catalog"
xml.book[0]  //is an object with following properties:
             //author, title, genre etc...
             //i.e., xml.book[0].author must return Gambardella, Matthew

hope that there was no similar question and sorry if there any, my bad, that i didn’t found. also, if there any documentation for this, particular case, please point to it, because i just couldn’t find it. there was plenty of documentation about xml parsing in various ways, but no info on this case.

thanks in advance.

  • 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-01T23:15:35+00:00Added an answer on June 1, 2026 at 11:15 pm

    Here is working LinqToXml code using these extension methods:

    [DebuggerDisplay("{Title}")]
    public class Catalog
    {
        XElement self;
        public Catalog(XElement catalog) { self = catalog; }
        public string Title { get { return self.Get("title", string.Empty); } }
        public Uri Link { get { return self.Get<Uri>("link", null); } }
        public Book[] Books
        {
            get { return _Books ?? (_Books = self.GetEnumerable("book", x => new Book(x)).ToArray()); }
        }
        Book[] _Books;
        [DebuggerDisplay("{Title} by {Author}")]
        public class Book
        {
            XElement self;
            public Book(XElement book) { self = book; }
            public string Id { get { return self.Get("id", string.Empty); } }
            public string Author { get { return self.Get("author", string.Empty); } }
            public string Title { get { return self.Get("title", string.Empty); } }
            public string Genre { get { return self.Get("genre", string.Empty); } }
            public decimal Price { get { return self.Get<decimal>("price", 0); } }
            public DateTime PublishDate { get { return self.Get("publish_date", DateTime.MinValue); } }
            public string Description { get { return self.Get("description", string.Empty); } }
        }
    }
    

    And to use it:

    Catalog catalog = new Catalog(XElement.Load(file)); // or .Parse(string)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following XML file: <?xml version=1.0 encoding=utf-8?> <Customers xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=Customer.xsd>
Let's say I have an XML file such as this: <root> <level1 name=level1A> <level2
Just say I have a file configuration.xml that a php script needs to parse
For reference, the code is for the motorola 68008. Say I have code such
Lets say a have a string such as this one: string txt = Lore
Say I have a simple object such as class Something { public int SomeInt
Say we have a base class green and such hieraachy tree: We have a
Say i have a string that i need to evaluate in javascript such as
Lets say I have a table with columns such as: ID Name City State
Let's say I have a WCF contract such as [ServiceContract] public interface IContract {

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.