R
raghudr
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<string> names = 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 "<signal> name 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
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<string> names = 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 "<signal> name 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