• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

reading xml with dataset

I am trying to read a XML file ..I am using the readxml method of the dataset..
ds.ReadXml("D:\\Backups\\InvMgmt\\test3.xml");
the XML file format is as below..
it can read all the columns except the the last two with double quotes. if I rename <col type="c001"> as <col2> i can read the value properly but not otherwise..how can i solve the problem?

<?xml version="1.0"?>
- <securityinfo>
- <security>
  <symbol>IRX.X</symbol>
  <id>141</id>
  <name>U.S. - 3mo T-Bill</name>
  <type>SEIR</type>
  <col type="c001">4.825</col>
  <col type="c046">0.0</col>
  </security>
0
saswati_m
Asked:
saswati_m
  • 3
  • 2
  • 2
1 Solution
 
R7AFCommented:
Do you mean you want to read the attribute value? You can use an xpath expression like:

security/col/@type

If this is not what you want, please be more specific.
0
 
saswati_mAuthor Commented:
No I do not want to read the attribute values..I just need the values of the elements like 141, 4.825,0.0..It does not read the values 4.825 or 0 but it reads correctly the value 141..how is that possible ?

I am  new to XML and would very much appreciate the help.
0
 
R7AFCommented:
Can you give the xslt or xpath you're using?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
saswati_mAuthor Commented:
I am not using any xslt path ...do I need to use one ?  I  am not really familiar with the concept..
I will actually be readin this file from a url..but for now I am just testing it by putting it in a file ..
can u please explain why I need to use xpath ? can i not directly read the values from the file?
0
 
anarki_jimbelCommented:
In a table in a dataset you have datatables. I believe datatables may have only unique column names that's why you are geting the error. So probably the only way to solve the problem is to rename elements.

There are other ways to read these values,like:

XmlDocument doc = new XmlDocument();
doc.Load(filepath);

XmlNodeList list = doc.GetElementsByTagName("col");
 and now you have two nodes to read from, and you can use something like:

XmlElement elOne = (XmlElement)list[0];
XmlElement elTwo = (XmlElement)list[1];


string val1 = elOne.InnerText; // or InnerXml
0
 
saswati_mAuthor Commented:
I really appreciate your input. I used your code and it worked!!!!
Thanks  A Lot  !!!!
0
 
anarki_jimbelCommented:
Cool! :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now