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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:55:39+00:00 2026-05-26T06:55:39+00:00

I have a Java generated (List Collection) XML format of: <java.util.Collections> <org.yccheok.jstock.engine.Stock> <code> <code>

  • 0

I have a Java generated (List Collection) XML format of:

<java.util.Collections>
   <org.yccheok.jstock.engine.Stock> 
     <code> 
       <code> RBS.L</code> 
     </code> 
     <symbol> 
       <symbol> ROYAL BK SCOTL GR</symbol> 
     </symbol> 
     <name> ROYAL BK SCOTL GR</name> 
     <board> London</board> 
     <industry> Unknown</industry> 
     <prevPrice> 23.74</prevPrice> 
     <openPrice> 23.41</openPrice> 
     <lastPrice> 24.4</lastPrice> 
     <highPrice> 24.855</highPrice> 
     <lowPrice> 23.0</lowPrice> 
     <volume> 51353968</volume> 
     <changePrice> 0.66</changePrice> 
     <changePricePercentage> 2.78</changePricePercentage> 
     <lastVolume> 795</lastVolume> 
     <buyPrice> 24.39</buyPrice> 
     <buyQuantity> 51203</buyQuantity> 
     <sellPrice> 24.4</sellPrice> 
     <sellQuantity> 370763</sellQuantity> 
     <secondBuyPrice> 0.0</secondBuyPrice> 
     <secondBuyQuantity> 0</secondBuyQuantity> 
     <secondSellPrice> 0.0</secondSellPrice> 
     <secondSellQuantity> 0</secondSellQuantity> 
     <thirdBuyPrice> 0.0</thirdBuyPrice> 
     <thirdBuyQuantity> 0</thirdBuyQuantity> 
     <thirdSellPrice> 0.0</thirdSellPrice> 
     <thirdSellQuantity> 0</thirdSellQuantity> 
     <calendar> 
       <time> 1319038099446</time> 
       <timezone> America/New_York</timezone> 
     </calendar> 
   </org.yccheok.jstock.engine.Stock>
</java.util.Collections>

I am trying to extract the tag values of the code inner tag and changePricePercentage in C#. I am also trying to pre-populate a DataTable with these values. How do I handle the inner tag of code as well? Even though I am no expert, here is my C# source code

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

namespace XMLParser
{
    class Program
    {
        static void Main(string[] args)
        {
            DataTable table = new DataTable();
            table.Columns.Add("code", typeof(string)); ;
            table.Columns.Add("changePricePercentage", typeof(double));
            // Create a new XmlDocument  
            XmlDocument doc = new XmlDocument();

            // Load data  
            doc.Load(@"C:\...\realtimestock.xml");

            // Set up namespace manager for XPath  

            // Get forecast with XPath  
            //XmlNodeList nodes = doc.SelectNodes("org.yccheok.jstock.engine.Stock", ns);
            XmlNodeList nodes = doc.SelectNodes("org.yccheok.jstock.engine.Stock");
            // You can also get elements based on their tag name and namespace,  
            // though this isn't recommended  
            //XmlNodeList nodes = doc.GetElementsByTagName("org.yccheok.jstock.engine.Stock");
            //                          "http://xml.weather.yahoo.com/ns/rss/1.0");  

            foreach (XmlNode node in nodes)
            {
                // Console.WriteLine("{0}: {1}, {2}F - {3}F",
                //                     node.Attributes["code"].InnerText,
                //                     node.Attributes["changePricePercentage"].InnerText);

                Console.WriteLine("1: {0} 2: {1}", node.Attributes["code"].InnerText,
node.Attributes["changePricePercentage"].InnerText);

                table.Rows.Add(node.Attributes["code"].InnerText, node.Attributes["changePricePercentage"].InnerText);

                Console.ReadKey();

            }
        }
    }
}

How would I get my code to accomplish this task?
P.S. This Stackoverflow editor would not accept my XML code properly so I had to edit with the actual symbol names. Sorry
Thanks

  • 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-26T06:55:40+00:00Added an answer on May 26, 2026 at 6:55 am

    Try this:

    XmlNodeList nodes = doc.SelectNodes("//org.yccheok.jstock.engine.Stock");
    
    foreach (XmlElement element in nodes)
    {
        Console.WriteLine("1: {0} 2: {1}", 
            element.SelectSingleNode("code").InnerText,
            element.SelectSingleNode("changePricePercentage").InnerText);
    }
    Console.ReadKey();
    

    Your code and changePricePercentage nodes are elements, not attributes, that was your mistake.

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

Sidebar

Related Questions

I have a problem while pasting my contents (or text) generated by Java code
I have a java.hprof.txt file (automatically generated after an OutOfMemoryError) which I would like
Say I have a binary file (generated with Java) containing a 32 bit int
I have a post-compilation step that manipulates the Java bytecode of generated classes. I'd
I have a Java servlet which generates XML, translates it with an XSLT stylesheet,
I have a Java string of XML content. I use Velocity to generate some
I have a multithreaded code that has to generated a set of objects and
I have Java string: String b = /feedback/com.school.edu.domain.feedback.Review$0/feedbackId); I also have generated pattern against
I have this schema and i'm using JAXB to generate java stub files. <?xml
I have some code generated from xsd files by xmlbeans-maven-plugin. Unfortunately generated code uses

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.