By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,383 Members | 2,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,383 IT Pros & Developers. It's quick & easy.

Problem with reading .xml file using Dataset method

P: n/a
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.Auto);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Error", MessageBoxButtons.OK);
return false;

}

//storing the names only to list

List<stringnames = 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@ADVANT" />
<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@ADVANT" />
<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@ADVANT" />
<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 "<signalname 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
Share this Question
Share on Google+
1 Reply


P: n/a
ra*****@gmail.com 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 discussion thread is closed

Replies have been disabled for this discussion.