473,651 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with reading .xml file using Dataset method

Hi all,

I am parsing an .xml file.My main intention is to retrieve the field
value:- "Name Value" which is "rag" and store

it in a List.

Fot that i wrote code like this:

//i am using dataset method to read the .xml files
DataSet pcXML = new DataSet("pcXML" );

//
try
{

pcXML.ReadXml(" filename.xml", XmlReadMode.Aut o);

}
catch (Exception ex)
{
MessageBox.Show (ex.Message,"Er ror", MessageBoxButto ns.OK);
return false;

}

//storing the names only to list

List<stringname s = new List<string>();

// Add the extracted variables to the list
foreach (DataRow pcRow in pcXML.Tables["Name"].Rows)
{
names.Add(pcRow[0].ToString());
}

The .xml file is given below
<Signal>
<Name Value="rag" />
<Real Value="21@ADVAN T" />
<Description Value="Best" />
<Min Value="0" />
<Max Value="40" />
<Unit Value="barh" />
<Item Value="XQ60" />
<MillisCylce Value="20" />
<Resolution Value="1" />
<DataType Value="VT" />
</Signal>
<Signal>
<Name Value="rock" />
<Real Value="21@ADVAN T" />
<Description Value="Best" />
<Min Value="0" />
<Max Value="40" />
<Unit Value="barh" />
<Item Value="XQ60" />
<MillisCylce Value="20" />
<Resolution Value="1" />
<DataType Value="VT" />
</Signal>

//The above code works fine if the .xml file is of the above format.I
am able to retrieve all the names and store in

the list.

------------------------------------------------------------------------------
Problem:

Now some .xml files are this format:

<Signal>
Name Value="rag" />
<Real Value="21@ADVAN T" />
<Description Value="Best" />
<Min Value="0" />
<Max Value="40" />
<Unit Value="barh" />
<Item Value="XQ60" />
<MillisCylce Value="20" />
<Resolution Value="1" />
<DataType Value="VT" />
<SubSignals>
<Signal BitIndex="0">
<Name Value="jack" />
<Reference Value="" />
<Description Value="AIR_PRG" />
<Min Value="11" />
<Max Value="13" />
<Unit Value="ACTIVE" />
<DataType Value="VT" />
</Signal>
<Signal BitIndex="1">
<Name Value="jae" />
<Reference Value="" />
<Description Value="AIR_PRG" />
<Min Value="11" />
<Max Value="13" />
<Unit Value="ACTIVE" />
<DataType Value="VT" />
</Signal>
<Signal BitIndex="2">
<Name Value="chuck" />
<Reference Value="" />
<Description Value="AIR_PRG" />
<Min Value="11" />
<Max Value="13" />
<Unit Value="ACTIVE" />
<DataType Value="VT" />
</Signal>
</SubSignals>
</Signal>

Problem is :

In the above .xml file format with my code when i try to read the .xml
file i am getting an exception "The

Table(signal) cannot be the child table to itself in nested
relations".

Here also i want to store only the "<signalnam e value" that is only
"rag" to my list.
I do not want to add any "subsignals " name value to the list.i want to
skip it.

can anyone tell me what changes i need to do to my above code.

thanks in advance,
RAGHU
Oct 8 '08 #1
1 1767
ra*****@gmail.c om wrote:
can anyone tell me what changes i need to do to my above code.
I don't think using a DataSet with that kind of XML structure is going
to work. Use XmlReader or XPathDocument/XPathNavigator or with .NET
3.5 LINQ to XML to parse that XML, those APIs can deal with any
well-formed XML document (respectively in the case of XmlReader and
XPathDocument even with any kind of well-formed fragment).
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
555
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have no way of knowing what the tables are, or what they contain. I am currently using the Dataset.WriteXML method passing an XMLWriter.
3
4587
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. I'm getting some strange results depending the input XML file I use. I was wondering if somebody could help me understand what is going on or point me to a good reference. The code for my program looks like this:
0
1453
by: chris.millar | last post by:
I am using the ReadXMLSchema method of system.data.dataset to read a schema into a dataset. I have an XML file that I build up and wish to do a .Update against a database. The dataset doesn't have a schema and takes the following form: xml: <?xml version="1.0" encoding="utf-8"?> <DataSetEntities xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:guids="urn:schemas-microsoft-com:guids" xmlns="C:/DACXML/EntityAttribute.xsd">
2
3379
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and then appends the data to a dataset that is built in the Page_Load code in the if(!isPostBack) block. When I try to add a row in the button click event code I get an error saying that "Object reference not set to an instance of an object". I'm...
5
8935
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the bottom of this posting.
8
2372
by: Thirsty Traveler | last post by:
I have a dataset that is returned from a sql server select that contains metadata and a cached dataset saved in an xml column. I would like to recover the dataset for use in generating a crystal pdf file. the rptds.ReadXml method can accept either a string file indicating a filename or a stream. the row.ToString() is the saved dataset. If I use this directly it throws an error because it is data and not a filename. I have a workaround seen...
9
22488
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What namespaces and classes should I use and how? -- dba123
4
18704
by: shibeta | last post by:
Hello, I have problem with DataGridView and BindingSource. I have created DataSet and added TableData to it with manualy created columns (without DataAdapter - I'm not using MSSQL). On the Form I put DataGridView and BindingSource, and connected them (BindingSource of course is also connected with DataSet). Next on the separated thread I'm reading data from DB and load them do DataSet (more preciselly, readed data I've saved as XML and...
4
3248
by: David | last post by:
Hi, (Sorry for duplicate post, finger trouble before I finished...) using C# 1.1 I am writing a winform app that collects a dataset from a webservice. At the same time I collect the data, I write the dataset out to the local disk using DataSet.WriteXml, so that if the webservice is not available,
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.