I have tried many way to read the value A180 in <p name="conDN">A180</p>
, but fail.
I would like to read all values for the below name:
- class, grade, id
- conDN, Code, product, serial
Attribute Name = name;
Attribute value = conDN;
i really no idea how to call A180
** I am newbie in C#.**
May the expert guide me on how to read it.
Thank you very much.
Below is the XML content:
<Subject class="High" grade="E21" id="78038751482">
<p name="conDN">A180</p>
<p name="Code">AA98073512</p>
<p name="product">ACN5677</p>
<p name="serial">AEXB18201</p>
</Subject>
<Subject class="Low" grade="E21" id="98721124">
<p name="conDN">B900</p>
<p name="Code">BA723512</p>
<p name="product">BG5677</p>
<p name="serial">BCB18148</p>
</Subject>
<Subject class="Middle" grade="E2022" id="52358523205">
<p name="conDN">C800</p>
<p name="Code">CA47351299</p>
<p name="product">CA5677</p>
<p name="serial">CTB18201</p>
</Subject>
Please find below is my code:
string attName = null;
string attValue = null;
do
{
reader.MoveToFirstAttribute();
attName = "class";
if (reader.MoveToAttribute(attName))
attValue = reader.ReadContentAsString();
tbox01.AppendText($"{attName} : {attValue} \n");
attName = "grade";
if (reader.MoveToAttribute(attName))
attValue = reader.ReadContentAsString();
tbox01.AppendText($"{attName} : {attValue} \n");
attName = "id";
if (reader.MoveToAttribute(attName))
attValue = reader.ReadContentAsString();
tbox01.AppendText($"{attName} : {attValue} \n");
//------------ Read Element --------------
reader.ReadToFollowing("p");
attName = "name";
if (reader.MoveToAttribute(attName))
attValue = reader.ReadContentAsString();
tbox01.AppendText($"{attName} : {attValue} \n");
tbox01.AppendText("-------------------------");
tbox01.AppendText(Environment.NewLine);
} while (reader.ReadToFollowing("Subject") );
Below is what i get with my code:
class : High
grade : E21
id : 78038751482
name : conDN
-------------------------
class : Low
grade : E21
id : 98721124
name : conDN
-------------------------
class : Middle
grade : E2022
id : 52358523205
name : conDN
-------------------------
------------ END -------------