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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:46:10+00:00 2026-06-06T01:46:10+00:00

I have an XML file that I’m trying to read from here , and

  • 0

I have an XML file that I’m trying to read from here, and have the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace XML
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlTextReader textReader = new XmlTextReader("secLendingXML.cfm.xml");
            while (textReader.Read())
            {
                switch (textReader.NodeType)
                {
                    case XmlNodeType.Element:
                        Console.WriteLine(textReader.Name);
                        Console.WriteLine(textReader.Value);
                        break;
                    case XmlNodeType.Text:
                        Console.WriteLine(textReader.Value);
                        break;
                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        Console.WriteLine(textReader.Name + " " + textReader.Value);
                        break;
                    case XmlNodeType.Comment:
                        Console.WriteLine(textReader.Value);
                        break;
                    case XmlNodeType.EndElement:
                        break;
                }
            }
            Console.ReadLine();
        }
    }
}

The code is working properly in the sense that it’s reading the nodes and returning the names. But, the issue is that I’m trying to also retrieve the data within the nodes. In other words, when it reads the first section after the test section, it will read:

slnc:DataSet
slnc:Group
slnc:Section
slnc:ActualAvailableToBorrow
*** here ***
slnc:oustandingLoans

This is where I want the textreader to read the following values within the node like
confidentiality="F", currency="USD", etc., but it just skips right to the
next section without reading these values!

<slnc:actualAvailableToBorrow xmlns:slnc="http://www.newyorkfed.org/xml/schemas/SecLending" 
      confidentiality="F" currency="USD" decimals="0" method="AA" 
      multiplier="5" securityLendingType="AA" status="A" value="1474"/>

How do I get the textreader to read the attribute values? It would be ideal for it to print the value “currency”, and then its value: “F”, and so on.

  • 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-06T01:46:11+00:00Added an answer on June 6, 2026 at 1:46 am

    Get a Single, Named Attribute

    Use XmlTextReader.GetAttribute (MSDN)

    case XmlNodeType.Element:
      Console.WriteLine(textReader.Name);
      Console.WriteLine(textReader.Value);
      Console.WriteLine(textReader.GetAttribute("currency"));
    

    One nice feature of this function: it will not cause an Exception if the attribute is not defined – it will simply return Null.

    Get All the Attributes

    Use XmlTextReader.MoveToAttribute (MSDN)

    Use the AttributeCount property in combination with MoveToAttribute:

    case XmlNodeType.Element:
      Console.WriteLine(textReader.Name);
      Console.WriteLine(textReader.Value);
      for (int attInd = 0; attInd < textReader.AttributeCount; attInd++){
          textReader.MoveToAttribute( attInd );
          Console.WriteLine(textReader.Name);
          Console.WriteLine(textReader.Value);
      }
      textReader.MoveToElement(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file that will be read many times from the source
I have an xml file that looks like the following. What I'm trying to
I have an XML file that I am trying to search using Java. I
I have a xml file that needs to be read from many many times.
I have an XML file that is very long, but here is a shot
I have an XML file that I'm trying to serialize into an object. Some
I have an xml file that I want to configure using a bash script.
I have an XML file that I'm trying to parse with Linq-to-XML. One of
I have an XML file that needs parsing in PHP. I am currenlty using
I have an XML file that looks like this. <collections id=my collections> <category id=my

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.